/** * Sets an error_uid header based on the given error response's {@link ErrorResponseBody#errorId()} and replaces the * {@link ErrorResponseBody} found in the {@link ResponseInfo#getContentForFullResponse()} with the String result of * calling {@link ErrorResponseBodySerializer#serializeErrorResponseBodyToString(ErrorResponseBody)} on {@link * #errorResponseBodySerializer}. The modified {@link ResponseInfo} is then sent to {@link * #sendFullResponse(io.netty.channel.ChannelHandlerContext, RequestInfo, ResponseInfo, ObjectMapper)} for passing * back to the client. * <p/> * NOTE: This assumes a full (not chunked) response, and uses {@link ResponseInfo#getContentForFullResponse()} to * retrieve the {@link ErrorResponseBody} object. Therefore this method will throw an {@link * IllegalArgumentException} if you pass in a response object that returns true for {@link * ResponseInfo#isChunkedResponse()}. */ public void sendErrorResponse(ChannelHandlerContext ctx, RequestInfo requestInfo, ResponseInfo<ErrorResponseBody> responseInfo) throws JsonProcessingException { if (responseInfo.isChunkedResponse()) { throw new IllegalArgumentException("The responseInfo argument is marked as being a chunked response, but " + "sendErrorResponse(...) only works with full responses"); } responseInfo.getHeaders().set("error_uid", responseInfo.getContentForFullResponse().errorId()); @SuppressWarnings("UnnecessaryLocalVariable") ErrorResponseBody bodyToSerialize = responseInfo.getContentForFullResponse(); if (bodyToSerialize != null) { String errorBodyAsString = errorResponseBodySerializer.serializeErrorResponseBodyToString(bodyToSerialize); //noinspection unchecked ((ResponseInfo) responseInfo).setContentForFullResponse(errorBodyAsString); } sendFullResponse(ctx, requestInfo, responseInfo, defaultResponseContentSerializer); }
/** * Sets an error_uid header based on the given error response's {@link ErrorResponseBody#errorId()} and replaces the * {@link ErrorResponseBody} found in the {@link ResponseInfo#getContentForFullResponse()} with the String result of * calling {@link ErrorResponseBodySerializer#serializeErrorResponseBodyToString(ErrorResponseBody)} on {@link * #errorResponseBodySerializer}. The modified {@link ResponseInfo} is then sent to {@link * #sendFullResponse(io.netty.channel.ChannelHandlerContext, RequestInfo, ResponseInfo, ObjectMapper)} for passing * back to the client. * <p/> * NOTE: This assumes a full (not chunked) response, and uses {@link ResponseInfo#getContentForFullResponse()} to * retrieve the {@link ErrorResponseBody} object. Therefore this method will throw an {@link * IllegalArgumentException} if you pass in a response object that returns true for {@link * ResponseInfo#isChunkedResponse()}. */ public void sendErrorResponse(ChannelHandlerContext ctx, RequestInfo requestInfo, ResponseInfo<ErrorResponseBody> responseInfo) throws JsonProcessingException { if (responseInfo.isChunkedResponse()) { throw new IllegalArgumentException("The responseInfo argument is marked as being a chunked response, but " + "sendErrorResponse(...) only works with full responses"); } responseInfo.getHeaders().set("error_uid", responseInfo.getContentForFullResponse().errorId()); @SuppressWarnings("UnnecessaryLocalVariable") ErrorResponseBody bodyToSerialize = responseInfo.getContentForFullResponse(); if (bodyToSerialize != null) { String errorBodyAsString = errorResponseBodySerializer.serializeErrorResponseBodyToString(bodyToSerialize); //noinspection unchecked ((ResponseInfo) responseInfo).setContentForFullResponse(errorBodyAsString); } sendFullResponse(ctx, requestInfo, responseInfo, defaultResponseContentSerializer); }