StreamResponse response = se.getResponse();
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; }
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; }
/** * 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); }
/** * 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; }
if (e instanceof StreamException) streamResponse = ((StreamException) e).getResponse();
@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); } };
StreamResponse response = se.getResponse();
@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); } } });