Skip to content

Commit

Permalink
feat: more detailed error report on BaseFileCloudService
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Mar 18, 2024
1 parent 896f231 commit 9d447f6
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ final class BaseFileCloudService implements FileCloudService {

connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setConnectTimeout(5000);

final var multipartBoundary = HttpUtil.generateBoundary();

Expand Down Expand Up @@ -82,7 +83,23 @@ final class BaseFileCloudService implements FileCloudService {
//noinspection deprecation
responseJson = JSON_PARSER.parse(reader).getAsJsonObject();
} catch (final IOException e) {
throw new IllegalStateException("Failed to read response from Artemis", e);
int status;
try {
status = connection.getResponseCode();
} catch (IOException ignored) {
// if getResponseCode() failed, just throw
// the original exception
throw new IllegalStateException("Failed to upload file, failed to get response code", e);
}

final String errorInfo;
try {
errorInfo = ((Readable) (connection::getErrorStream)).readAsUTF8String();
} catch (final IOException ignored) {
throw new IllegalStateException("Failed to upload file, failed to read error stream", e);
}

throw new IllegalStateException("Failed to upload file, status: " + status + ", error: " + errorInfo, e);
}

final var success = responseJson.get("ok").getAsBoolean();
Expand Down

0 comments on commit 9d447f6

Please sign in to comment.