use of org.apache.flink.runtime.rest.FlinkHttpObjectAggregator in project flink by apache.
the class AbstractHandler method handleException.
private CompletableFuture<Void> handleException(Throwable throwable, ChannelHandlerContext ctx, HttpRequest httpRequest) {
ClusterEntryPointExceptionUtils.tryEnrichClusterEntryPointError(throwable);
FlinkHttpObjectAggregator flinkHttpObjectAggregator = ctx.pipeline().get(FlinkHttpObjectAggregator.class);
if (flinkHttpObjectAggregator == null) {
log.warn("The connection was unexpectedly closed by the client.");
return CompletableFuture.completedFuture(null);
}
int maxLength = flinkHttpObjectAggregator.maxContentLength() - OTHER_RESP_PAYLOAD_OVERHEAD;
if (throwable instanceof RestHandlerException) {
RestHandlerException rhe = (RestHandlerException) throwable;
String stackTrace = ExceptionUtils.stringifyException(rhe);
String truncatedStackTrace = Ascii.truncate(stackTrace, maxLength, "...");
if (log.isDebugEnabled()) {
log.error("Exception occurred in REST handler.", rhe);
} else if (rhe.logException()) {
log.error("Exception occurred in REST handler: {}", rhe.getMessage());
}
return HandlerUtils.sendErrorResponse(ctx, httpRequest, new ErrorResponseBody(truncatedStackTrace), rhe.getHttpResponseStatus(), responseHeaders);
} else {
log.error("Unhandled exception.", throwable);
String stackTrace = String.format("<Exception on server side:%n%s%nEnd of exception on server side>", ExceptionUtils.stringifyException(throwable));
String truncatedStackTrace = Ascii.truncate(stackTrace, maxLength, "...");
return HandlerUtils.sendErrorResponse(ctx, httpRequest, new ErrorResponseBody(Arrays.asList("Internal server error.", truncatedStackTrace)), HttpResponseStatus.INTERNAL_SERVER_ERROR, responseHeaders);
}
}
Aggregations