Fix web-app api throwing an error and add full errors to the StateDumper

This commit is contained in:
Lukas Rieger (Blue) 2022-08-02 18:14:38 +02:00
parent 38f23f2374
commit d4f00682a6
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
2 changed files with 28 additions and 20 deletions

View File

@ -14,7 +14,7 @@
import java.util.stream.Stream;
public class WebAppImpl implements WebApp {
private static final String IMAGE_ROOT_PATH = "images";
private static final Path IMAGE_ROOT_PATH = Path.of("data", "images");
private final Plugin plugin;
@ -43,9 +43,10 @@ public String createImage(BufferedImage image, String path) throws IOException {
Path webRoot = getWebRoot().toAbsolutePath();
String separator = webRoot.getFileSystem().getSeparator();
Path webDataRoot = webRoot.resolve("data");
Path imagePath = webDataRoot.resolve(Path.of(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
Path imageRootFolder = webRoot.resolve(IMAGE_ROOT_PATH);
Path imagePath = imageRootFolder.resolve(Path.of(path.replace("/", separator) + ".png")).toAbsolutePath();
Files.createDirectories(imagePath.getParent());
Files.deleteIfExists(imagePath);
Files.createFile(imagePath);
@ -64,6 +65,7 @@ public Map<String, String> availableImages() throws IOException {
Map<String, String> availableImagesMap = new HashMap<>();
if (Files.exists(imageRootPath)) {
try (Stream<Path> fileStream = Files.walk(imageRootPath)) {
fileStream
.filter(p -> !Files.isDirectory(p))
@ -80,9 +82,11 @@ public Map<String, String> availableImages() throws IOException {
.replace(separator, "/");
availableImagesMap.put(key, value);
} catch (IllegalArgumentException ignore) {}
} catch (IllegalArgumentException ignore) {
}
});
}
}
return availableImagesMap;
}

View File

@ -32,6 +32,8 @@
import org.spongepowered.configurate.serialize.SerializationException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@ -168,7 +170,9 @@ private void dumpInstance(Object instance, ConfigurationOptions options, Configu
}
} catch (Exception ex) {
node.set("Error: " + ex);
StringWriter stringWriter = new StringWriter();
ex.printStackTrace(new PrintWriter(stringWriter));
node.set("Error: " + ex + " >> " + stringWriter);
}
}