show error, don't crash

This commit is contained in:
Manuel Friedli 2023-04-01 00:21:38 +02:00 committed by Gitea
parent ff047efd85
commit 305c26c215

View file

@ -105,15 +105,15 @@ public class LabyrinthServer {
exchange.sendResponseHeaders(302, -1);
return;
}
final Labyrinth labyrinth = new Labyrinth(width, height, id);
final byte[] render;
try {
final Labyrinth labyrinth = new Labyrinth(width, height, id);
render = output.render(labyrinth);
} catch (Exception e) {
responseHeaders.add("Content-type", "text/plain; charset=UTF-8");
exchange.sendResponseHeaders(500, 0);
final OutputStream responseBody = exchange.getResponseBody();
responseBody.write(("Error: " + e).getBytes(StandardCharsets.UTF_8));
responseBody.write(("Error: " + e.getMessage()).getBytes(StandardCharsets.UTF_8));
responseBody.flush();
return;
}