Search in sources :

Example 1 with UnauthorizedException

use of io.gravitee.am.gateway.handler.scim.exception.UnauthorizedException in project gravitee-access-management by gravitee-io.

the class ErrorHandler method handle.

@Override
public void handle(RoutingContext routingContext) {
    if (routingContext.failed()) {
        Throwable throwable = routingContext.failure();
        // management exception (resource not found, server error, ...)
        if (throwable instanceof AbstractManagementException) {
            AbstractManagementException technicalManagementException = (AbstractManagementException) throwable;
            handleException(routingContext, technicalManagementException.getHttpStatusCode(), technicalManagementException.getMessage(), null);
        // oauth2 exception (token invalid exception)
        } else if (throwable instanceof OAuth2Exception) {
            OAuth2Exception oAuth2Exception = (OAuth2Exception) throwable;
            handleException(routingContext, oAuth2Exception.getHttpStatusCode(), oAuth2Exception.getMessage(), null);
        } else if (throwable instanceof SCIMException) {
            SCIMException scimException = (SCIMException) throwable;
            handleException(routingContext, scimException.getHttpStatusCode(), scimException.getMessage(), scimException.getScimType());
        } else if (throwable instanceof HttpException) {
            if (401 == ((HttpException) throwable).getStatusCode()) {
                UnauthorizedException unauthorizedException = new UnauthorizedException();
                handleException(routingContext, unauthorizedException.getHttpStatusCode(), unauthorizedException.getMessage(), null);
            }
        } else if (throwable instanceof PolicyChainException) {
            PolicyChainException policyChainException = (PolicyChainException) throwable;
            handleException(routingContext, policyChainException.statusCode(), policyChainException.key() + " : " + policyChainException.getMessage(), null);
        } else {
            logger.error(throwable.getMessage(), throwable);
            if (routingContext.statusCode() != -1) {
                routingContext.response().setStatusCode(routingContext.statusCode()).end();
            } else {
                routingContext.response().setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end();
            }
        }
    }
}
Also used : AbstractManagementException(io.gravitee.am.service.exception.AbstractManagementException) SCIMException(io.gravitee.am.gateway.handler.scim.exception.SCIMException) UnauthorizedException(io.gravitee.am.gateway.handler.scim.exception.UnauthorizedException) HttpException(io.vertx.ext.web.handler.HttpException) 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 SCIMException (io.gravitee.am.gateway.handler.scim.exception.SCIMException)1 UnauthorizedException (io.gravitee.am.gateway.handler.scim.exception.UnauthorizedException)1 PolicyChainException (io.gravitee.am.gateway.policy.PolicyChainException)1 AbstractManagementException (io.gravitee.am.service.exception.AbstractManagementException)1 HttpException (io.vertx.ext.web.handler.HttpException)1