Skip to content

Error handling #6

Closed
Closed

Description

@jvherweg

This issue is to keep track of the discussion about to handle errors internally. Main discussions were had in a pull request here and here.

Currently the errors thrown store a status code internally so the ResponseWriter knows which status code to return in the case of an error. The advantage is that this allows for easily adding new errors in the future. The disadvantage is that this makes some of the classes less independent and mixes some reponsabilities. For example, this makes it more difficult to have CompositeAsyncHandler as a separate package. Not that this is necessary but it might be an indication that there is an issue with this.

Activity

  1. added
    ❓question
    on Jun 5, 2020
  2. RubenVerborgh commented on Aug 12, 2020

    @RubenVerborgh
    Member

    We need to fix this. When reviewing #52, I see Http pop up everywhere because of this choice, and that feels very wrong, as this layer is HTTP-independent.

  3. rubensworks commented on Aug 12, 2020

    @rubensworks
    Contributor

    Maybe we want to make use of the factory pattern here, where we have an ErrorFactory that can be called to constructor errors of different types (that we define). During dependency injection, we could pass an HttpErrorFactory that would create HTTP-specific errors for our internal error types.

    This would allows us to create other error factories later on, such as IpfsErrorfactory.

  4. jvherweg commented on Aug 12, 2020

    @jvherweg
    MemberAuthor

    That would then have to be a dependency for most classes though.

    The other option is going to non-Http errors as was already suggested before and have a handler somewhere at the end that converts them to status codes (probably called by the responseWriter). And if new errors are introduced they would require also making a new handler for them (which can be combined in a CompositeHandler as usual then).

    Both of these do make #23 a bit harder to solve I think :D

  5. RubenVerborgh commented on Aug 12, 2020

    @RubenVerborgh
    Member

    A factory is a definitely viable avenue indeed; it does feel a bit heavy to always have this injected (given how common errors are).

    That would make me lean towards a more adapter-like solution, where (for instance) the back-end layer throws a simple "Not Found" / "Not Exists" error, which is a data object that is later translated into the right HTTP error. So basically, factory strategy, but the factory takes in data objects such that not all classes need this factory.

  6. added 2 commits that reference this issue on Sep 14, 2020
  7. RubenVerborgh commented on Jul 22, 2021

    @RubenVerborgh
    Member

    We have nice HTML errors now; I think that's enough.

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

    error-handling❓question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions