Conversation
5f903a5 to
f779ba6
Compare
| return { text: buffer.toString() }; | ||
| }, | ||
|
|
||
| CustomError: class CustomError extends DomainError {}, |
There was a problem hiding this comment.
Rarely you need an error per-method.
It is much easier to manage errors defined in a separate file and exported everywhere.
This way format/code/message/interface is much easier to control.
| errors: { | ||
| EARGA: 'Invalid argument: a', | ||
| EARGB: 'Invalid argument: b', | ||
| }, | ||
|
|
||
| onError(error) { | ||
| if (error.code in this.errors) { |
There was a problem hiding this comment.
It is unlikely that you will know all errors that are thrown from inside the domain. Or more accurately - unlikely that you want to list them in every method. It adds a lot of chore to the api definition.
IMO it is better to manage this per-error and let domain decide which to throw.
| cause?: Error; | ||
| } | ||
|
|
||
| export class Error extends global.Error { |
There was a problem hiding this comment.
It is better to have some content object to each error. Only cause may not be enough.
And people will be forced to Object.assign(new Error(), { my custom fields })
| stack: string; | ||
| code?: number | string; | ||
| cause?: Error; | ||
| toError(errors: Errors): Error; |
| const pg: Database; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I"d suggest to have toJSON() and toUserError() defined as global interfaces as wel.
No description provided.