-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added support for cause #116
Conversation
I dont think that this is an appropriate implementation. Cause is usually an optional parameter. |
new FastifyError('message', {
casue: new Error('casue')
}) i'm also okay with this idea, using named arguments new FastifyError({
message: 'message',
casue: new Error('casue')
}) |
Also |
I am thinking how to make this backward compatible since the function |
@DanieleFedeli I have no idea, but i think it's okay to release a major version if needed |
It doesn't really matter for the function Error(...args) {
if(args.length && typeof args.at(-1) === 'object' && 'cause' in args.at(-1)) {
this.cause = args.pop()
}
} |
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.
lgtm
Should I fix for node 14? |
Yes, please. |
index.js
Outdated
this.code = code | ||
this.name = 'FastifyError' | ||
this.statusCode = statusCode | ||
|
||
if (args.length && typeof args.at(-1) === 'object' && 'cause' in args.at(-1)) { |
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.
if (args.length && typeof args.at(-1) === 'object' && 'cause' in args.at(-1)) { | |
const lastElement = args.length - 1 | |
if (lastElement !== -1 && args[lastElement] && typeof args[lastElement] === 'object' && 'cause' in args[lastElement]) { |
I added the args[lastElement] for the case that the last element is null.
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.
not tested.
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.
lgtm
@Uzlopak could you do a final check? |
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.
LGTM
@mcollina :) |
Checklist
This PR target #112. It will be possible to create an error with cause.
Typescript and Documentation changes will be applied after the main idea is approved.
npm run test
andnpm run benchmark
and the Code of conduct