@Override
    public HttpResponse authFailed(HttpService delegate, ServiceRequestContext ctx, HttpRequest req,
                                   @Nullable Throwable cause) throws Exception {
        if (cause != null) {
            if (logger.isWarnEnabled()) {
                logger.warn("Unexpected exception during OAuth 2 authorization.", cause);
            }
            return HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR, MediaType.PLAIN_TEXT_UTF_8,
                                   "Unexpected exception during OAuth 2 authorization.");
        }

        // obtain ERROR_CODE and ERROR_TYPE from the context set by OAuth2TokenIntrospectionAuthorizer
        final Integer errorCode = ctx.attr(ERROR_CODE);
        final String errorType = ctx.attr(ERROR_TYPE);
        if (errorCode == null) {
            // something else happened - do not authorize
            // we may omit the expected scope for the generic response
            return unauthorized(errorType, accessTokenType, realm, scope);
        }

        switch (errorCode) {
            case 400:
                return badRequest(errorType);
            case 401:
                return unauthorized(errorType, accessTokenType, realm, scope);
            case 403:
                return forbidden(errorType);
            default:
                return HttpResponse.of(errorCode);
        }
    }
Invoked when the authorization of the specified {@link HttpRequest} has failed.
Composes OAuth 2.0 authorization error response of the following types:
<ul>
   <li>invalid_request - 400 Bad Request</li>
   <li>invalid_token - 401 Unauthorized</li>
   <li>insufficient_scope - 403 Forbidden</li>
</ul>
as per <a href="https://datatracker.ietf.org/doc/html/rfc6750#rfc.section.3.1">
    The OAuth 2.0 Authorization Framework: Bearer Token Usage</a>
oauth2/src/main/java/com/linecorp/armeria/server/auth/oauth2/OAuth2AuthorizationFailureHandler.java