Skip to content

Should the error type be Box<Error>? #6

@mjkillough

Description

@mjkillough

We currently define aitch::Error to be an alias for Box<Error>.

This was because:

  • We wanted middleware to be as generic as possible, while requiring as few type parameters as possible. The hope that this would encourage users to create and share re-usable middleware, without having to specify an error type everywhere.
  • It wasn't clear what downstream middleware/servers could do with the information in an error type. If a handler returns an error type, it's unlikely that the application could do much more than return a generic HTTP 500.

Since making this decision, we added the handler::static_files handlers, which attempt to catch io::Error and display a HTTP 404. These currently downcast the Box<Error>, which feels a little gross. Is there a better way?

Would aitch be more powerful if it somehow allowed users to specify a custom error type? What would that API look like?

Feedback very welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    open-questionUnanswered design questions - feedback wanted!

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions