Skip to content

Allow handling errors with error handlers #622

@matthewmcgarvey

Description

@matthewmcgarvey

Description

In the docs for Kemal, one of the example error handlers is

error 403 do
  "Access Forbidden!"
end

The only way for this error handler to work is for somewhere in the code to set the status code on the response and then raise a Kemal::Exceptions::CustomException (or ancestor of it).

I believe this kind of error would be better handled like

error AccessForbiddenError do
  "Access Forbidden"
end

We could go into these error handlers with the default status of 500 unless the error is a custom Kemal error where the status could be specified on it.

What do you think?

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