Skip to content

Commit

Permalink
fix(httpapi): log more detail on HTTP API exceptions (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Oct 12, 2021
1 parent 2fd72d9 commit 19855bc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/io/cryostat/net/web/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,22 @@ public void start() throws FlightRecorderException, SocketException, UnknownHost
exception = new HttpStatusException(500, ctx.failure());
}

String payload =
exception.getPayload() != null
? exception.getPayload()
: exception.getMessage();
if (!HttpStatusCodeIdentifier.isServerErrorCode(exception.getStatusCode())) {
logger.warn(exception);
logger.warn(
"HTTP {}: {}\n{}",
exception.getStatusCode(),
payload,
ExceptionUtils.getStackTrace(exception).trim());
} else {
logger.error(exception);
logger.error(
"HTTP {}: {}\n{}",
exception.getStatusCode(),
payload,
ExceptionUtils.getStackTrace(exception).trim());
}

if (exception.getStatusCode() == 401) {
Expand All @@ -153,11 +165,6 @@ public void start() throws FlightRecorderException, SocketException, UnknownHost
.end(gson.toJson(resp));
} else {
// kept for V1 API handler compatibility
String payload =
exception.getPayload() != null
? exception.getPayload()
: exception.getMessage();

if (ExceptionUtils.hasCause(exception, HttpStatusException.class)) {
payload +=
" caused by " + ExceptionUtils.getRootCauseMessage(exception);
Expand Down

0 comments on commit 19855bc

Please sign in to comment.