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();
}
}
}
}
Aggregations