-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling proposal #233
base: master
Are you sure you want to change the base?
Conversation
5f903a5
to
f779ba6
Compare
const filePath = `/content/${name}.md`; | ||
const buffer = application.resources.get(filePath); | ||
if (!buffer) return new Error('Content is not found'); | ||
return { text: buffer.toString() }; | ||
}, | ||
|
||
CustomError: class CustomError extends DomainError {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this method?
@@ -23,3 +23,27 @@ declare global { | |||
const pg: Database; | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I"d suggest to have toJSON() and toUserError() defined as global interfaces as wel.
No description provided.