下面列出了org.springframework.web.client.HttpClientErrorException#getLocalizedMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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);
}
@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());
}