diff --git a/mod-fabric/resources/assets/pixelchat/lang/en_us.json b/mod-fabric/resources/assets/pixelchat/lang/en_us.json index aa69a57..d36334a 100644 --- a/mod-fabric/resources/assets/pixelchat/lang/en_us.json +++ b/mod-fabric/resources/assets/pixelchat/lang/en_us.json @@ -1,5 +1,6 @@ { "pixelchat.uploading": "Uploading", - "pixelchat.upload_failed": "Upload failed", + "pixelchat.upload_failed.no_error": "Upload failed", + "pixelchat.upload_failed.error": "Upload failed - %s", "pixelchat.upload_completed": "Upload completed" } \ No newline at end of file diff --git a/mod-fabric/src/eu/e99/pixelchat/fabric/image/ImageUploads.java b/mod-fabric/src/eu/e99/pixelchat/fabric/image/ImageUploads.java index 98eb7c5..63ece30 100644 --- a/mod-fabric/src/eu/e99/pixelchat/fabric/image/ImageUploads.java +++ b/mod-fabric/src/eu/e99/pixelchat/fabric/image/ImageUploads.java @@ -46,21 +46,32 @@ public class ImageUploads { this.minecraft.send(() -> bossBars.add(bossBar.getUuid(), bossBar)); String url = null; + Throwable error = null; + for (String host : this.hosts) { try { url = this.upload(host, path); + error = null; break; } catch (Throwable e) { + error = e; PixelChat.LOGGER.warn("Failed to upload", e); } } // IntelliJ complains otherwise String finalUrl = url; + Throwable finalError = error; + this.minecraft.send(() -> { if (finalUrl == null) { PixelChat.LOGGER.error("No uploader succeeded"); - bossBar.setName(Text.translatable("pixelchat.upload_failed")); + + Text message = finalError == null ? + Text.translatable("pixelchat.upload_failed.no_error") : + Text.translatable("pixelchat.upload_failed.error", finalError.getMessage()); + + bossBar.setName(message); bossBar.setPercent(1.0f); bossBar.setColor(BossBar.Color.RED); return; @@ -100,7 +111,7 @@ public class ImageUploads { ); if (res.statusCode() != 201) { String body = res.body(); - throw new RuntimeException(String.format("Failed to upload, expected status 201, got %d, body: %s", res.statusCode(), body)); + throw new RuntimeException(String.format("%d: %s", res.statusCode(), body)); } String id = res.body(); diff --git a/server/src/eu/e99/pixelchat/server/ImageHandler.java b/server/src/eu/e99/pixelchat/server/ImageHandler.java index d8a6891..546d695 100644 --- a/server/src/eu/e99/pixelchat/server/ImageHandler.java +++ b/server/src/eu/e99/pixelchat/server/ImageHandler.java @@ -6,10 +6,10 @@ import io.javalin.http.Context; import io.javalin.http.HttpStatus; import org.apache.commons.imaging.ImageFormats; import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.ImagingException; import org.slf4j.Logger; import java.awt.image.BufferedImage; -import java.io.IOException; import java.io.InputStream; import java.time.Instant; import java.time.temporal.TemporalAmount; @@ -51,22 +51,22 @@ public class ImageHandler { status(HttpStatus.CREATED). contentType(ContentType.TEXT_PLAIN). result(id); - } catch (IllegalArgumentException ignored) { + } catch (ImagingException | IllegalArgumentException ignored) { ctx .status(HttpStatus.BAD_REQUEST) .result("Unrecognized image format"); - } catch (IOException e) { - ctx - .status(HttpStatus.INTERNAL_SERVER_ERROR) - .result("Internal Server Error"); - - this.logger.error("Failed to upload image", e); } catch (OutOfMemoryError e) { ctx .status(HttpStatus.INSUFFICIENT_STORAGE) .result("Insufficient storage on server"); this.logger.error("Out of memory", e); + } catch (Throwable e) { + ctx + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .result("Internal Server Error"); + + this.logger.error("Failed to upload image", e); } } @@ -86,7 +86,7 @@ public class ImageHandler { status(HttpStatus.OK). contentType(ContentType.IMAGE_PNG). result(png); - } catch (IOException e) { + } catch (Throwable e) { ctx .status(HttpStatus.INTERNAL_SERVER_ERROR) .result("Internal Server Error");