Search in sources :

Example 1 with RestError

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());
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestError(com.epam.ta.reportportal.commons.exception.rest.RestError) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception)

Aggregations

RestError (com.epam.ta.reportportal.commons.exception.rest.RestError)1 ResponseEntity (org.springframework.http.ResponseEntity)1 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)1