private HandlerResponse<T> createErrorResponse(Exception e, int statusCode) { ErrorResponse errorResp = unwrapException(e); try { return new HandlerResponse<>(encode(errorResp), statusCode); } catch (IOException e1) { // TODO provide a canned ErrorResponse // If we can't serialize the error message, we can't give a meaningful error to caller. // Just try to not unnecessarily create more exceptions. if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } }
private HandlerResponse<T> createErrorResponse(Exception e, int statusCode) { ErrorResponse errorResp = unwrapException(e); try { return new HandlerResponse<>(encode(errorResp), statusCode); } catch (IOException e1) { // TODO provide a canned ErrorResponse // If we can't serialize the error message, we can't give a meaningful error to caller. // Just try to not unnecessarily create more exceptions. if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } }
return new HandlerResponse<>(encode(response), HTTP_OK); } catch (Exception e) { ErrorResponse errorResp = unwrapException(e); return new HandlerResponse<>(encode(errorResp), HTTP_INTERNAL_SERVER_ERROR); } catch (IOException e1) {
/** * Compute a response for the given request, handling errors generated by that computation. * * @param serializedRequest The caller's request. * @return A {@link Response} with additional context about that response. */ public HandlerResponse<T> apply(T serializedRequest) { try { final Service.Request request = decode(serializedRequest); final Service.Response response = request.accept(service); return new HandlerResponse<>(encode(response), HTTP_OK); } catch (Exception e) { return convertToErrorResponse(e); } }
/** * Compute a response for the given request, handling errors generated by that computation. * * @param serializedRequest The caller's request. * @return A {@link Response} with additional context about that response. */ public HandlerResponse<T> apply(T serializedRequest) { try { final Service.Request request = decode(serializedRequest); final Service.Response response = request.accept(service); return new HandlerResponse<>(encode(response), HTTP_OK); } catch (Exception e) { return convertToErrorResponse(e); } }