Capture Request Exception

This commit is contained in:
2023-05-21 19:50:23 +08:00
parent f19c4b8e77
commit 82477321d1
3 changed files with 260 additions and 248 deletions

View File

@ -50,6 +50,7 @@ public final class OpenCommandHandler implements Router {
public static void handle(Context context) {
var plugin = OpenCommandPlugin.getInstance();
try {
var config = plugin.getConfig();
var data = plugin.getData();
var now = new Date();
@ -177,6 +178,9 @@ public final class OpenCommandHandler implements Router {
}
}
context.json(new JsonResponse(403, "forbidden"));
} catch (Throwable ex) {
plugin.getLogger().error("[OpenCommand] handler error.", ex);
}
}
private static void cleanupExpiredCodes() {

View File

@ -51,6 +51,7 @@ public final class OpenCommandOnlyHttpHandler implements Router {
public static void handle(Context context) {
var plugin = OpenCommandPlugin.getInstance();
try {
var config = plugin.getConfig();
var data = plugin.getData();
var now = new Date();
@ -200,6 +201,9 @@ public final class OpenCommandOnlyHttpHandler implements Router {
}
}
context.json(new JsonResponse(403, "forbidden"));
} catch (Exception ex) {
plugin.getLogger().error("[OpenCommand] handler error.", ex);
}
}
private static void cleanupExpiredCodes() {

View File

@ -111,9 +111,11 @@ public final class OpenCommandPlugin extends Plugin {
config = JsonUtils.decode(Files.readString(configFile.toPath(), StandardCharsets.UTF_8),
OpenCommandConfig.class);
} catch (Exception exception) {
config = new OpenCommandConfig();
getLogger().error("[OpenCommand] There was an error while trying to load the configuration from config.json. Please make sure that there are no syntax errors. If you want to start with a default configuration, delete your existing config.json.");
}
if (config == null) {
config = new OpenCommandConfig();
}
}
try {
runMode = Grasscutter.getConfig().server.runMode;
@ -132,9 +134,11 @@ public final class OpenCommandPlugin extends Plugin {
data = JsonUtils.decode(Files.readString(dataFile.toPath(), StandardCharsets.UTF_8),
OpenCommandData.class);
} catch (Exception exception) {
data = new OpenCommandData();
getLogger().error("[OpenCommand] There was an error while trying to load the data from data.json. Please make sure that there are no syntax errors. If you want to start with a default data, delete your existing data.json.");
}
if (data == null) {
data = new OpenCommandData();
}
}
}