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()
}
} |
|
Should I fix for node 14? |
|
Yes, please. |
index.js
Outdated
| 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.
| 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.
|
@Uzlopak could you do a final check? |
|
@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 testandnpm run benchmarkand the Code of conduct