use of org.apache.flink.runtime.rest.messages.ErrorResponseBody in project flink by apache.
the class PipelineErrorHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest message) {
// we can't deal with this message. No one in the pipeline handled it. Log it.
logger.warn("Unknown message received: {}", message);
HandlerUtils.sendErrorResponse(ctx, message, new ErrorResponseBody("Bad request received."), HttpResponseStatus.BAD_REQUEST, Collections.emptyMap());
}
use of org.apache.flink.runtime.rest.messages.ErrorResponseBody in project flink by apache.
the class PipelineErrorHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
logger.warn("Unhandled exception", cause);
HandlerUtils.sendErrorResponse(ctx, false, new ErrorResponseBody("Internal server error: " + cause.getMessage()), HttpResponseStatus.INTERNAL_SERVER_ERROR, responseHeaders);
}
use of org.apache.flink.runtime.rest.messages.ErrorResponseBody in project flink by apache.
the class HistoryServerStaticFileServerHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (ctx.channel().isActive()) {
LOG.error("Caught exception", cause);
HandlerUtils.sendErrorResponse(ctx, false, new ErrorResponseBody("Internal server error."), INTERNAL_SERVER_ERROR, Collections.emptyMap());
}
}
use of org.apache.flink.runtime.rest.messages.ErrorResponseBody in project flink by apache.
the class RestClient method parseResponse.
private static <P extends ResponseBody> CompletableFuture<P> parseResponse(JsonResponse rawResponse, JavaType responseType) {
CompletableFuture<P> responseFuture = new CompletableFuture<>();
final JsonParser jsonParser = objectMapper.treeAsTokens(rawResponse.json);
try {
P response = objectMapper.readValue(jsonParser, responseType);
responseFuture.complete(response);
} catch (IOException originalException) {
// lets see if it is an ErrorResponse instead
try {
ErrorResponseBody error = objectMapper.treeToValue(rawResponse.getJson(), ErrorResponseBody.class);
responseFuture.completeExceptionally(new RestClientException(error.errors.toString(), rawResponse.getHttpResponseStatus()));
} catch (JsonProcessingException jpe2) {
// if this fails it is either the expected type or response type was wrong, most
// likely caused
// by a client/search MessageHeaders mismatch
LOG.error("Received response was neither of the expected type ({}) nor an error. Response={}", responseType, rawResponse, jpe2);
responseFuture.completeExceptionally(new RestClientException("Response was neither of the expected type(" + responseType + ") nor an error.", originalException, rawResponse.getHttpResponseStatus()));
}
}
return responseFuture;
}
use of org.apache.flink.runtime.rest.messages.ErrorResponseBody in project flink by apache.
the class LeaderRetrievalHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, RoutedRequest routedRequest) {
HttpRequest request = routedRequest.getRequest();
OptionalConsumer<? extends T> optLeaderConsumer = OptionalConsumer.of(leaderRetriever.getNow());
optLeaderConsumer.ifPresent(gateway -> {
try {
respondAsLeader(channelHandlerContext, routedRequest, gateway);
} catch (Exception e) {
logger.error("Error while responding to the http request.", e);
HandlerUtils.sendErrorResponse(channelHandlerContext, request, new ErrorResponseBody("Error while responding to the http request."), HttpResponseStatus.INTERNAL_SERVER_ERROR, responseHeaders);
}
}).ifNotPresent(() -> HandlerUtils.sendErrorResponse(channelHandlerContext, request, new ErrorResponseBody("Service temporarily unavailable due to an ongoing leader election. Please refresh."), HttpResponseStatus.SERVICE_UNAVAILABLE, responseHeaders));
}
Aggregations