wiktor-obrebski / type-safe-errors

Simple type-safe errors for TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom errors should inherit js `Error`

wiktor-obrebski opened this issue · comments

In some cases, especially when using .unsafePromise(), the custom domain errors can be thrown.
The function should not be used in normal application flow, but can be useful in tests.

https://mochajs.org/ test runner do not works well with throwed / rejected errors that do not inherit by Error.
This is good enough reason to change proposed error classes style in the library documentation.
Proposition of new error style:

class InvalidCredentialsError extends Error {
  name = 'InvalidCredentials' as const;
}