Skip to content

Feature Request: Bearer Auth - allow custom error response content type #5218

Description

@max-got

What is the feature you are proposing?

Problem

Bearer auth error responses can't be sent as anything other than application/json or text/plain. The content type is hardcoded in throwHTTPException...

Request

Since we want to adhere to RFC 9457 problem details (application/problem+json) everywhere, it would be nice if we are able to customize the content type in the response. Since the middleware throws an HTTPException with a pre-built res, an onError handler can't fix the headers afterwards either. See for Reference bearer-auth/index.ts

Idea

Let MessageFunction also return a Response and use it as-is (set WWW-Authenticate if missing). Backwards compatible. Alternatively a contentType option next to message (?)

Current workaround: throw from the message function and rebuild the WWW-Authenticate header manually in the app.

Activity

  1. changed the title [-]Feature Request: Bearer Auth - allow custom error response content type (e.g. `application/problem+json`)[/-] [+]Feature Request: Bearer Auth - allow custom error response content type[/+] on Aug 12, 2026
  2. Jr-14 commented on Aug 13, 2026

    @Jr-14
    Contributor

    Just learnt about RFC 9457 and thought it was pretty cool! I think it'd be really helpful to see first class support for application/problem+json in Hono, especially its strong type inference around request/response types and RPC. I'd definitely use this in our production environments 👍🏼

  3. Jr-14 commented on Aug 14, 2026

    @Jr-14
    Contributor

    This might be in consideration for this v5 comment #5106 (comment)

  4. yusukebe commented on Aug 15, 2026

    @yusukebe
    Member

    Hi @max-got

    Thank you for the request. I think the middleware should allow users to set error responses flexibly. Letting MessageFunction return Response is one of the solutions, but we have to consider.

    If it doesn't introduce a breaking change, we can include it in a minor version update. Don't need to include v5.

  5. AiAlchemist0 commented on Aug 19, 2026

    @AiAlchemist0

    Opened http://github.com/honojs/hono/pull/ so message can return a Response (RFC 9457) without breaking existing string/object messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions