Skip to content

Commit

Permalink
[FLINK-11134][rest] Do not log stacktrace for handled exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Jan 10, 2019
1 parent f692d37 commit c06e7a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ protected void respondAsLeader(ChannelHandlerContext ctx, RoutedRequest routedRe
try {
request = MAPPER.readValue("{}", untypedResponseMessageHeaders.getRequestClass());
} catch (JsonParseException | JsonMappingException je) {
log.error("Request did not conform to expected format.", je);
throw new RestHandlerException("Bad request received.", HttpResponseStatus.BAD_REQUEST, je);
throw new RestHandlerException("Bad request received. Request did not conform to expected format.", HttpResponseStatus.BAD_REQUEST, je);
}
} else {
try {
ByteBufInputStream in = new ByteBufInputStream(msgContent);
request = MAPPER.readValue(in, untypedResponseMessageHeaders.getRequestClass());
} catch (JsonParseException | JsonMappingException je) {
log.error("Failed to read request.", je);
throw new RestHandlerException(
String.format("Request did not match expected format %s.", untypedResponseMessageHeaders.getRequestClass().getSimpleName()),
HttpResponseStatus.BAD_REQUEST,
Expand Down Expand Up @@ -164,6 +162,11 @@ protected void respondAsLeader(ChannelHandlerContext ctx, RoutedRequest routedRe
});
} catch (RestHandlerException rhe) {
inFlightRequestTracker.deregisterRequest();
if (log.isDebugEnabled()) {
log.error("Exception occurred in REST handler.", rhe);
} else {
log.error("Exception occurred in REST handler: {}", rhe.getMessage());
}
HandlerUtils.sendErrorResponse(
ctx,
httpRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ private Tuple2<ResponseBody, HttpResponseStatus> errorResponse(Throwable throwab
Throwable error = ExceptionUtils.stripCompletionException(throwable);
if (error instanceof RestHandlerException) {
final RestHandlerException rhe = (RestHandlerException) error;
log.error("Exception occurred in REST handler.", rhe);
if (log.isDebugEnabled()) {
log.error("Exception occurred in REST handler.", rhe);
} else {
log.error("Exception occurred in REST handler: {}", rhe.getMessage());
}
return Tuple2.of(new ErrorResponseBody(rhe.getMessage()), rhe.getHttpResponseStatus());
} else {
log.error("Implementation error: Unhandled exception.", error);
Expand Down

0 comments on commit c06e7a5

Please sign in to comment.