added error 500 handler for favicon request

This commit is contained in:
Jonas_Jones 2023-09-06 02:42:22 +02:00
parent 668094844d
commit 879b6c85e3

View file

@ -141,11 +141,21 @@ public class HttpServer implements Runnable {
// Set appropriate response headers // Set appropriate response headers
dataOut.write("HTTP/1.1 200 OK\r\n".getBytes(StandardCharsets.UTF_8)); dataOut.write("HTTP/1.1 200 OK\r\n".getBytes(StandardCharsets.UTF_8));
dataOut.write("Date: %s\r\n".formatted(Instant.now()).getBytes(StandardCharsets.UTF_8)); dataOut.write("Date: %s\r\n".formatted(Instant.now()).getBytes(StandardCharsets.UTF_8));
if (fileRequested.equals("/api/v1/servericon")) { if (fileRequested.equals("/api/v1/favicon")) {
int contentLength;
byte[] serverIcon;
try {
dataOut.write("Content-Type: image/png\r\n".getBytes(StandardCharsets.UTF_8)); dataOut.write("Content-Type: image/png\r\n".getBytes(StandardCharsets.UTF_8));
// Get server icon from ApiHandler // Get server icon from ApiHandler
byte[] serverIcon = ApiRequestsUtil.getServerIcon(); serverIcon = ApiRequestsUtil.getServerIcon();
int contentLength = serverIcon.length; contentLength = serverIcon.length;
} catch (Exception e) {
serverIcon = ApiRequests.internalServerError().getBytes(StandardCharsets.UTF_8);
VerboseLogger.error("Error getting server icon from ApiHandler: " + e.getMessage());
dataOut.write("Content-Type: application/json\r\n".getBytes(StandardCharsets.UTF_8));
contentLength = serverIcon.length;
}
dataOut.write(("Content-Length: " + contentLength + "\r\n").getBytes(StandardCharsets.UTF_8)); dataOut.write(("Content-Length: " + contentLength + "\r\n").getBytes(StandardCharsets.UTF_8));
dataOut.write("\r\n".getBytes(StandardCharsets.UTF_8)); // Blank line before content dataOut.write("\r\n".getBytes(StandardCharsets.UTF_8)); // Blank line before content