Skip to content

Commit d6d8cd1

Browse files
committed
Improve the error message
1 parent 26c9cf7 commit d6d8cd1

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/main/java/org/maxgamer/quickshop/util/language/text/TextManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public void load() {
7373
}
7474
}
7575
} catch (Exception e) {
76+
if(e.getMessage().contains("Did not get expected response code, got 403 for")) {
77+
plugin.getLogger().log(Level.WARNING, "The language " + availableLanguage+" didn't configure correctly, please report to QuickShop.", e);
78+
continue;
79+
}
7680
plugin.getLogger().log(Level.WARNING, "Couldn't update the translation for locale " + availableLanguage, e);
7781
}
7882
}

src/main/java/org/maxgamer/quickshop/util/language/text/distributions/crowdin/CrowdinOTA.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.nio.charset.StandardCharsets;
2424
import java.util.*;
2525
import java.util.concurrent.TimeUnit;
26+
import java.util.logging.Level;
2627

2728
public class CrowdinOTA implements Distribution {
2829
protected static final String CROWDIN_OTA_HOST = "https://distributions.crowdin.net/daf1a8db40f132ce157c457xrm4/";
@@ -37,7 +38,7 @@ public CrowdinOTA(QuickShop plugin) {
3738
Util.getCacheFolder().mkdirs();
3839
}
3940

40-
private byte[] requestWithCache(@NotNull String url, @Nullable File saveTo) {
41+
private byte[] requestWithCache(@NotNull String url, @Nullable File saveTo) throws IOException {
4142
byte[] data = requestCachePool.getIfPresent(url);
4243
if (data == null) {
4344
try {
@@ -48,9 +49,6 @@ private byte[] requestWithCache(@NotNull String url, @Nullable File saveTo) {
4849
if (saveTo != null)
4950
response.saveContent(saveTo);
5051
return response.asBytes();
51-
} catch (IOException e) {
52-
e.printStackTrace();
53-
return null;
5452
} catch (InterruptedException e) {
5553
e.printStackTrace();
5654
}
@@ -62,7 +60,13 @@ private byte[] requestWithCache(@NotNull String url, @Nullable File saveTo) {
6260
@Nullable
6361
public Manifest getManifest() {
6462
String url = CROWDIN_OTA_HOST + "manifest.json";
65-
String data = new String(requestWithCache(url,null), StandardCharsets.UTF_8);
63+
String data = null;
64+
try {
65+
data = new String(requestWithCache(url,null), StandardCharsets.UTF_8);
66+
} catch (IOException e) {
67+
plugin.getLogger().log(Level.WARNING,"Failed to download manifest.json, multi-language system won't work");
68+
return null;
69+
}
6670
if (StringUtils.isEmpty(data))
6771
return null;
6872
return JsonUtil.getGson().fromJson(data, Manifest.class);
@@ -71,7 +75,13 @@ public Manifest getManifest() {
7175
@Nullable
7276
public String getManifestJson() {
7377
String url = CROWDIN_OTA_HOST + "manifest.json";
74-
String data = new String(requestWithCache(url,null), StandardCharsets.UTF_8);
78+
String data;
79+
try {
80+
data = new String(requestWithCache(url,null), StandardCharsets.UTF_8);
81+
} catch (IOException e) {
82+
plugin.getLogger().log(Level.WARNING,"Failed to download manifest.json, multi-language system won't work");
83+
return null;
84+
}
7585
if (StringUtils.isEmpty(data))
7686
return null;
7787
return data;
@@ -143,7 +153,7 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
143153
String url = CROWDIN_OTA_HOST + "content" + fileCrowdinPath.replace("%locale%", crowdinLocale);
144154
byte[] bin = requestWithCache(url,cachedDataFile);
145155
if (bin == null)
146-
throw new IOException("Couldn't download translation from remote server. If you see any error like \"404 Not Found\", please report it to QuickShop.");
156+
throw new IOException("Couldn't download translation from remote server.");
147157
// update cache index
148158
data = Util.readToString(cachedDataFile);
149159
cacheMetadata.set(pathHash + ".timestamp", manifest.getTimestamp());

0 commit comments

Comments
 (0)