StreamResponse response = se.getResponse(); stripHeaders(builder.getHeaders(), HttpConstants.CONTENT_ENCODING, HttpConstants.CONTENT_LENGTH); response = builder.setHeaders(headers).build(uncompressedStream); ex = new StreamException(response);
@Override public void onStreamError(Throwable throwable, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) { if (throwable instanceof StreamException) { StreamException ex = (StreamException) throwable; StreamResponse response = ex.getResponse(); response.getEntityStream().setReader(new DrainReader()); nextFilter.onError(new StreamException(response.builder().build(EntityStreams.emptyStream()), ex.getMessage(), ex.getCause()), requestContext, wireAttrs); } else { nextFilter.onError(throwable, requestContext, wireAttrs); } } });
private boolean ignoreLog(Throwable ex) { if (ex instanceof StreamException) { StreamException streamException = (StreamException)ex; return streamException.getResponse() != null; } if (ex instanceof RestException) { RestException restException = (RestException)ex; return restException.getResponse() != null; } return false; }
nextFilter.onError(new StreamException(streamResponse, ex), requestContext, wireAttrs);
@Override public void onSuccess(RestResponse result) { callback.onSuccess(new RestException(result, streamException.getMessage(), streamException.getCause())); } }, addContentLengthHeader);
private boolean logFullException(Throwable ex) { if (ex instanceof StreamException) { StreamException streamException = (StreamException)ex; return streamException.getResponse() != null; } if (ex instanceof RestException) { RestException restException = (RestException)ex; return restException.getResponse() != null; } return true; }
/** * Create a StreamException based on the RestException * @param restException the rest Exception * @return the StreamException that's created based on rest exception */ public static StreamException toStreamException(final RestException restException) { return new StreamException(toStreamResponse(restException.getResponse()), restException.getMessage(), restException.getCause()); }
StreamResponse response = se.getResponse(); stripHeaders(builder.getHeaders(), HttpConstants.CONTENT_ENCODING, HttpConstants.CONTENT_LENGTH); response = builder.setHeaders(headers).build(uncompressedStream); ex = new StreamException(response);
/** * Converts a StreamException to RestException * @param streamException the stream exception to be converted * @param callback the callback to be invoked when the rest exception is constructed * @param addContentLengthHeader whether to add content length header for the rest response */ public static void toRestException(final StreamException streamException, final Callback<RestException> callback, final boolean addContentLengthHeader) { toRestResponse(streamException.getResponse(), new Callback<RestResponse>() { @Override public void onError(Throwable e) { callback.onError(e); } @Override public void onSuccess(RestResponse result) { callback.onSuccess(new RestException(result, streamException.getMessage(), streamException.getCause())); } }, addContentLengthHeader); }
public static StreamException buildStreamException(RestLiResponseException restLiResponseException, StreamDataCodec codec) { RestLiResponse restLiResponse = restLiResponseException.getRestLiResponse(); StreamResponseBuilder responseBuilder = new StreamResponseBuilder() .setHeaders(restLiResponse.getHeaders()) .setCookies(CookieUtil.encodeSetCookies(restLiResponse.getCookies())) .setStatus(restLiResponse.getStatus().getCode()); EntityStream<ByteString> entityStream = codec.encodeMap(restLiResponse.getDataMap()); StreamResponse response = responseBuilder.build(EntityStreamAdapters.fromGenericEntityStream(entityStream)); return new StreamException(response, restLiResponseException.getCause()); } }
/** * Returns true if the given throwable indicates a server-side error. */ private boolean isServerError(Throwable throwable) { if (throwable instanceof RestException) { RestException restException = (RestException) throwable; if (restException.getResponse() != null) { return matchErrorStatus(restException.getResponse().getStatus()); } } else if (throwable instanceof StreamException) { StreamException streamException = (StreamException) throwable; if (streamException.getResponse() != null) { return matchErrorStatus(streamException.getResponse().getStatus()); } } // default to false return false; }
nextFilter.onError(new StreamException(streamResponse, ex), requestContext, wireAttrs);
if (e instanceof StreamException) streamResponse = ((StreamException) e).getResponse();
@Override public void onResponse(TransportResponse<StreamResponse> response) { if (response.hasError()) { response = TransportResponseImpl.error(new RemoteInvocationException("Failed to get response from server for URI " + uri, response.getError()), response.getWireAttributes()); } else if (!RestStatus.isOK(response.getResponse().getStatus())) { response = TransportResponseImpl.error(new StreamException(response.getResponse(), "Received error " + response.getResponse() .getStatus() + " from server for URI " + uri), response.getWireAttributes()); } callback.onResponse(response); } };
@Override public void onResponse(TransportResponse<StreamResponse> response) { if (response.hasError()) { final Throwable ex = response.getError(); if (ex instanceof StreamException) { callback.onResponse(TransportResponseImpl.success(((StreamException) ex).getResponse(), response.getWireAttributes())); return; } } callback.onResponse(response); } };