Prerequisites
Fastify version
5.7.2
Plugin version
12.5.0
Node.js version
24
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
any
Description
Current stack can return AggregateError instead of an actual error directly, which means, method
requestImpl strips every information about original error, when passing it to onError handler (AggregateError.message is always empty).
While this case makes the problem more visible, it is a generally problematic, that handler does not receive original error at all, in any case.
Error example:
{
"code": "ECONNREFUSED",
"errors": [
{
"errno": -111,
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "::1",
"port": 8080
},
{
"errno": -111,
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 8080
}
],
"stack": "AggregateError [ECONNREFUSED]: \n at internalConnectMultiple (node:net:1134:18)\n at afterConnectMultiple (node:net:1715:7)\n at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)"
}
My suggestion is to pass the cause to the errors returned by this, as FastifyError already has support for this.
onError(this, { error: new InternalServerError(err.message, {cause: err}) })
I can prepare a PR, if this would be acceptable fix.
Link to code that reproduces the bug
https://github.com/mdvorak/fastify-reply-from-error
Expected Behavior
Original error should be accessible in the handler
Prerequisites
Fastify version
5.7.2
Plugin version
12.5.0
Node.js version
24
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
any
Description
Current stack can return
AggregateErrorinstead of an actual error directly, which means, methodrequestImplstrips every information about original error, when passing it toonErrorhandler (AggregateError.messageis always empty).While this case makes the problem more visible, it is a generally problematic, that handler does not receive original error at all, in any case.
Error example:
{ "code": "ECONNREFUSED", "errors": [ { "errno": -111, "code": "ECONNREFUSED", "syscall": "connect", "address": "::1", "port": 8080 }, { "errno": -111, "code": "ECONNREFUSED", "syscall": "connect", "address": "127.0.0.1", "port": 8080 } ], "stack": "AggregateError [ECONNREFUSED]: \n at internalConnectMultiple (node:net:1134:18)\n at afterConnectMultiple (node:net:1715:7)\n at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)" }My suggestion is to pass the
causeto the errors returned by this, as FastifyError already has support for this.I can prepare a PR, if this would be acceptable fix.
Link to code that reproduces the bug
https://github.com/mdvorak/fastify-reply-from-error
Expected Behavior
Original error should be accessible in the handler