Java Code Examples for org.springframework.web.client.HttpClientErrorException#getLocalizedMessage()

The following examples show how to use org.springframework.web.client.HttpClientErrorException#getLocalizedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomRestExceptionHandler.java    From xxproject with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler({ OAuth2Exception.class })
public ResponseEntity<Object> handleOAuth2Exception(HttpClientErrorException ex, WebRequest request) {
    final String error = "Digits oauth authorization failed" ;
    final ApiError apiError = new ApiError(HttpStatus.FORBIDDEN, ex.getLocalizedMessage(), error);

    return new ResponseEntity<Object>(apiError, new HttpHeaders(), HttpStatus.FORBIDDEN);
}
 
Example 2
Source File: CustomRestExceptionHandler.java    From xxproject with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler({ AccessDeniedException.class })
public ResponseEntity<Object> handleAccessDeniedException(HttpClientErrorException ex, WebRequest request) {
    final String error = "Digits access authorization failed" ;
    final ApiError apiError = new ApiError(HttpStatus.FORBIDDEN, ex.getLocalizedMessage(), error);

    return new ResponseEntity<Object>(apiError, new HttpHeaders(), HttpStatus.FORBIDDEN);
}
 
Example 3
Source File: GlobalExceptionHandler.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler({ HttpClientErrorException.class })
public ResponseEntity<TdpExceptionDto> handleError(HttpClientErrorException e) {

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);

    String code = e.getStatusCode().toString();
    String message = e.getMessage();
    String localizedMessage = e.getLocalizedMessage();
    String statusText = e.getStatusText();

    TdpExceptionDto exceptionDto = new TdpExceptionDto(code, null, message, localizedMessage, statusText, null);

    return new ResponseEntity<>(exceptionDto, httpHeaders, e.getStatusCode());
}