/**
     * @see
     *     org.springframework.web.client.DefaultResponseErrorHandler#handleError(org.springframework.http.client.ClientHttpResponse)
     */
    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
      HttpStatus statusCode = getHttpStatusCode(response);
      switch (statusCode.series()) {
        case CLIENT_ERROR:
          handleClientError(statusCode);

          super.handleError(response);

        case SERVER_ERROR:
          super.handleError(response);
        default:
          throw new RestClientException("Unknown status code [" + statusCode + "]");
      }
    }
Ejemplo n.º 2
0
 @Override
 public void handleError(ClientHttpResponse response) throws IOException {
   HttpStatus statusCode = getHttpStatusCode(response);
   if (statusCode == HttpStatus.UNAUTHORIZED) {
     loginController.start(this);
   } else {
     super.handleError(response);
   }
 }
    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
      MediaType contentType = response.getHeaders().getContentType();
      if (contentType != null
          && (response.getStatusCode().value() == 400 || response.getStatusCode().value() == 401)) {
        if (JSON_MEDIA_TYPE.includes(contentType)) {
          try {
            throw getSerializationService().deserializeJsonError(response.getBody());
          } catch (SerializationException e) {
            throw new OAuth2Exception(
                "Error getting the access token, and unable to read the details of the error in the JSON response.",
                e);
          }
        } else if (FORM_MEDIA_TYPE.includes(contentType)) {
          MultiValueMap<String, String> map = FORM_MESSAGE_CONVERTER.read(null, response);
          throw getSerializationService().deserializeError(map.toSingleValueMap());
        }
      }

      super.handleError(response);
    }