@Nonnull public static Response fail(@Nonnull Response response) throws ResponseStatusException { throw new ResponseStatusException("Unexpected status: " + response.getStatusCode(), response); } }
@Override @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public boolean execute(@Nonnull final ApplicationLink applicationLink, @Nonnull final ApplicationId applicationId, @Nonnull final ApplicationLinkRequestFactory factory) throws IOException, CredentialsRequiredException, ResponseException, AuthenticationConfigurationException { try { configurator.enable(incoming, outgoing, applicationLink, factory); return true; } catch (AuthenticationConfigurationException ex) { ResponseStatusException cause = findCauseOfType(ex, ResponseStatusException.class); if (cause != null) { if (equalsStatus(cause.getResponse(), FORBIDDEN) || equalsStatus(cause.getResponse(), UNAUTHORIZED)) { return false; } } throw ex; } }
int statusCode = ex.getResponse().getStatusCode(); if (statusCode == 401) connectionErrors.add("Unexpected error when connecting to '" + applicationLink.getName() + "' (" + ex.getMessage() + ")");
int statusCode = ex.getResponse().getStatusCode(); if (statusCode == 401) throw new CredentialsRequiredException(applicationLink.createAuthenticatedRequestFactory(), ex.getMessage());
@Nonnull public static Response checkStatus(@Nonnull Response response, @Nonnull Iterable<Status> expectedStatuses) throws ResponseStatusException { checkNotNull(expectedStatuses, "expectedStatuses"); checkNotNull(response, "response"); Status responseStatus = Status.fromStatusCode(response.getStatusCode()); if (!contains(expectedStatuses, responseStatus)) { throw new ResponseStatusException("Unexpected status: " + response.getStatusCode(), response); } return response; }
@Override @SuppressWarnings("ConstantConditions") public ApplinkStatusException createMatchingError(String message, Throwable original) { ResponseStatusException statusException = findCauseOfType(original, ResponseStatusException.class); Response response = statusException.getResponse(); // response should generally always be available, but it's subject to well-behaved response handlers which // is sometimes outside of our control, so let's fall back to an "unknown" status in case there's no // response to figure it out from return response != null ? new ResponseApplinkStatusException(new UnexpectedResponseStatusError(response), statusException) : new SimpleApplinkStatusException(ApplinkErrorType.UNEXPECTED_RESPONSE_STATUS, "<UNKNOWN STATUS>", statusException); } }
public String handle(final Response response) throws ResponseException { if (!response.isSuccessful()) { throw new ResponseStatusException("Unexpected response received. Status code: " + response.getStatusCode(), response); } return response.getResponseBodyAsString(); } }
public String handle(final Response response) throws ResponseException { if (!response.isSuccessful()) { throw new ResponseStatusException("Unexpected response received. Status code: " + response.getStatusCode(), response); } return response.getResponseBodyAsString(); } }
@Override public String handle(Response response) throws ResponseException { String body = response.getResponseBodyAsString(); Status status = Status.fromStatusCode(response.getStatusCode()); if (status == null || status.getFamily() != Status.Family.SUCCESSFUL) { log.warn("Unexpected response status: {}, body:\n\n{}", response.getStatusCode(), body); throw new ResponseStatusException("Unexpected response status: " + response.getStatusCode(), response); } return body; } }