Skip to content

Error proposal #6

@mprudnik

Description

@mprudnik

There was a discussion about custom domain errors at the course meeting (QA 28/02/2023).
Proposed variants were separate class per error or general DomainError class with an internal map of allowed messages.

Instead, I propose having one class per domain with factories of allowed errors.

class DomainError extends Error {
...
}

class MessengerError extends DomainError {
...

  static invalidPermission() {
    return new MessengerError('Permission denied');
  }
  
  static notFound() {
    return new MessengerError('Not found');
  }
  
  // and so on...
}

This neither requires defining a class per each error (1 proposal) nor requires additional functionality to check if a general purpose error received an allowed message (2 proposal).
This also adds static checks and autocompletion.

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