/** * @return true if this proxy has a configured exception mapper */ public boolean hasExceptionMapper() { return getExceptionMapper() != null; }
@Override public void onError(final Request request, final Throwable throwable) { handleError(throwable, request, null); }
@SuppressWarnings({ "rawtypes" }) protected void sendRequest(final RequestBuilder requestBuilder, final String body, final ResponseDemarshallingCallback demarshallingCallback) { sendRequest(requestBuilder, body, demarshallingCallback, true); }
((AbstractJaxrsProxy) proxy).setSuccessCodes(Lists.newArrayList(successCodes)); ((AbstractJaxrsProxy) proxy).setRemoteCallback(callback); ((AbstractJaxrsProxy) proxy).setErrorCallback(errorCallback); ((AbstractJaxrsProxy) proxy).setRequestCallback(requestCallback); ((AbstractJaxrsProxy) proxy).setBaseUrl(baseUrl); return proxy;
if (firstTry && statusCode == 403 && response.getHeader(Constants.ERRAI_CSRF_TOKEN_HEADER) != null) { ClientCSRFTokenCache.setAssignedCSRFToken(response.getHeader(Constants.ERRAI_CSRF_TOKEN_HEADER)); sendRequest(requestBuilder, requestBody, demarshallingCallback, false); final ErrorCallback<?> errorCallback = getErrorCallback(); if (hasExceptionMapper()) { throwable = unmarshallException(response); throwable = new ResponseException("Response returned with status=" + response.getStatusCode(), response); handleError(throwable, request, response);
final ResponseDemarshallingCallback demarshallingCallback, final boolean firstTry) { final RemoteCallback remoteCallback = getRemoteCallback(); try { handleError(throwable, null, null);
protected void handleError(final Throwable throwable, final Request request, final Response response) { final ErrorCallback<?> errorCallback = getErrorCallback(); if (errorCallback != null) { if (errorCallback instanceof RestErrorCallback) { ((RestErrorCallback) errorCallback).error(request, throwable); } else { /* * Because of type erasure, there's no way to know if an ErrorCallback that doesn't implement RestErrorCallback takes * a request as an argument. But in some cases we want to wrap callbacks (such as in Caller<T>) to further control when * they are executed, and this is done in code upstream of RestErrorCallback. * * Thus, here we simply try to invoke with a request, and fallback to passing null if we get a casting exception. */ try { ((ErrorCallback<? super Request>) errorCallback).error(request, throwable); } catch (final ClassCastException e) { logger.debug("Class cast exception when invoking error callback with request object: {}", request); logger.debug("Invoking error callback again with null."); errorCallback.error(null, throwable); } } } else { GWT.log(throwable.getMessage(), throwable); } }
/** * Uses the configured {@link ClientExceptionMapper} to unmarshal the * {@link Response} into a {@link Throwable}. * * @param response */ protected Throwable unmarshallException(final Response response) { return getExceptionMapper().fromResponse(response); }