Skip to content

Allow setting response status code in HandleServerError #10718

@miunau

Description

@miunau

Describe the problem

I have business logic that throws well-formed errors with HTTP status codes. The errors are shared between several applications (API, web front-end, etc.).

Currently, it seems like if the code is dropping down to the HandleServerError hook, it always returns a 500 if the status wasn't defined before it was triggered, and there's no way to change the status while in the hook.

Describe the proposed solution

I would like to be able to set the response status inside the hook:

export const handleError: HandleServerError = ({ error, event, status }) => {
status(404);

(or via some other way)

Alternatives considered

Alternative to this seems to be to write my own wrapper and call the business logic through it, rethrowing error(status, message) which seems inelegant.

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions