Search in sources :

Example 1 with UmaException

use of io.gravitee.am.common.exception.uma.UmaException in project gravitee-access-management by gravitee-io.

the class ExceptionHandler method handle.

@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        Throwable throwable = routingContext.failure();
        if (throwable instanceof OAuth2Exception) {
            OAuth2Exception oAuth2Exception = (OAuth2Exception) throwable;
            OAuth2ErrorResponse oAuth2ErrorResponse = new OAuth2ErrorResponse(oAuth2Exception.getOAuth2ErrorCode());
            oAuth2ErrorResponse.setDescription(oAuth2Exception.getMessage());
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").setStatusCode(oAuth2Exception.getHttpStatusCode()).end(Json.encodePrettily(oAuth2ErrorResponse));
        } else if (throwable instanceof UmaException) {
            UmaException umaException = (UmaException) throwable;
            UMAErrorResponse umaErrorResponse = new UMAErrorResponse(umaException.getError()).setTicket(umaException.getTicket()).setRedirectUser(umaException.getRedirectUser()).setInterval(umaException.getInterval()).setRequiredClaims(this.from(umaException));
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").setStatusCode(umaException.getStatus()).end(Json.encodePrettily(umaErrorResponse));
        } else if (throwable instanceof PolicyChainException) {
            PolicyChainException policyChainException = (PolicyChainException) throwable;
            OAuth2ErrorResponse oAuth2ErrorResponse = new OAuth2ErrorResponse(policyChainException.key());
            oAuth2ErrorResponse.setDescription(policyChainException.getMessage());
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").setStatusCode(policyChainException.statusCode()).end(Json.encodePrettily(oAuth2ErrorResponse));
        } else if (throwable instanceof HttpException) {
            routingContext.response().setStatusCode(((HttpException) throwable).getStatusCode()).end();
        } else {
            logger.error("An exception occurs while handling incoming request", throwable);
            if (routingContext.statusCode() != -1) {
                routingContext.response().setStatusCode(routingContext.statusCode()).end();
            } else {
                routingContext.response().setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end();
            }
        }
    }
}
Also used : UMAErrorResponse(io.gravitee.am.gateway.handler.oauth2.service.response.UMAErrorResponse) UmaException(io.gravitee.am.common.exception.uma.UmaException) HttpException(io.vertx.ext.web.handler.HttpException) OAuth2ErrorResponse(io.gravitee.am.gateway.handler.oauth2.service.response.OAuth2ErrorResponse) PolicyChainException(io.gravitee.am.gateway.policy.PolicyChainException) OAuth2Exception(io.gravitee.am.common.exception.oauth2.OAuth2Exception)

Aggregations

OAuth2Exception (io.gravitee.am.common.exception.oauth2.OAuth2Exception)1 UmaException (io.gravitee.am.common.exception.uma.UmaException)1 OAuth2ErrorResponse (io.gravitee.am.gateway.handler.oauth2.service.response.OAuth2ErrorResponse)1 UMAErrorResponse (io.gravitee.am.gateway.handler.oauth2.service.response.UMAErrorResponse)1 PolicyChainException (io.gravitee.am.gateway.policy.PolicyChainException)1 HttpException (io.vertx.ext.web.handler.HttpException)1