use of com.epam.ta.reportportal.commons.exception.rest.RestError in project service-authorization by reportportal.
the class OAuthErrorHandler method translate.
@Override
public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
if (e instanceof OAuth2Exception) {
ResponseEntity<OAuth2Exception> translate = super.translate(e);
OAuth2Exception body = translate.getBody();
body.addAdditionalInformation("message", body.getMessage());
body.addAdditionalInformation("error_code", String.valueOf(ErrorType.ACCESS_DENIED.getCode()));
return translate;
} else {
RestError restError = errorResolver.resolveError(e);
OAuth2Exception exception = OAuth2Exception.create(String.valueOf(restError.getErrorRS().getErrorType().getCode()), restError.getErrorRS().getMessage());
exception.addAdditionalInformation("message", restError.getErrorRS().getMessage());
return new ResponseEntity<>(exception, restError.getHttpStatus());
}
}
Aggregations