Skip to content

Allow RequireHeaderAuthorization Middleware to Support Custom HTTP Status Code and Error Message #402

@deveasyclick

Description

@deveasyclick

The RequireHeaderAuthorization middleware currently throws a 403 Forbidden status code when authorization fails. However, in many cases, a 401 Unauthorized status code is more appropriate per HTTP standards, as it indicates missing or invalid authentication credentials. Additionally, there’s no way to customize the error message to provide more context to the client.

I had to create a custom middleware to replicate the functionality of RequireHeaderAuthorization but return a 401 status code and a custom error message. This workaround is not ideal, as it duplicates code.

Proposed Solution

Add configuration options to RequireHeaderAuthorization to allow developers to specify:

  • A custom HTTP status code (e.g., 401 instead of 403).
  • A custom error message to be returned in the response body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions