You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the feature has not already been requested
馃殌 Feature Proposal
I would love to use fastify-sensible. But in my case I check if the payload is empty and I want to set the "Not found" generic error using the reply.notFound() function.
However, it seems that it automatically also triggers a send again or something..?
Anyway, the function call will cause errors in onSend too bad 馃槩 (I do see the "not found" JSON message btw when calling the API, you only get those internal errors):
[14:29:07 UTC] ERROR: Promise errored, but reply.sent = true was set
reqId: "req-1"
err: {
"type": "Error",
"message": "Cannot write headers after they are sent to the client",
"stack":
Error [ERR_HTTP_HEADERS_SENT]: Cannot write headers after they are sent to the client
at ServerResponse.writeHead (node:_http_server:345:11)
at /media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/error-handler.js:42:19
at fallbackErrorHandler (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/error-handler.js:127:3)
at handleError (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/error-handler.js:34:5)
at onErrorHook (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/reply.js:839:5)
at wrapOnSendEnd (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/reply.js:563:5)
at next (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/hooks.js:297:7)
at onSendHookRunner (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/hooks.js:317:3)
at onSendHook (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/reply.js:549:5)
at Reply.send (/media/melroy/Data/Projects/erp-backend/node_modules/fastify/lib/reply.js:162:5)
"code": "ERR_HTTP_HEADERS_SENT"
}
Motivation
Currently I was creating my own errors like so, but I would like to leverage Fastify sensible in the onSendinstead of reinventing the wheel here:
reply.code(404).header('content-type','application/json; charset=utf-8')// Not found messageconststringify=fastJson({type: 'object',properties: {message: {type: 'string'}}})constmessage={message: 'Not found'}returndone(null,stringify(message))
Prerequisites
馃殌 Feature Proposal
I would love to use fastify-sensible. But in my case I check if the payload is empty and I want to set the "Not found" generic error using the
reply.notFound()
function.However, it seems that it automatically also triggers a send again or something..?
Anyway, the function call will cause errors in
onSend
too bad 馃槩 (I do see the "not found" JSON message btw when calling the API, you only get those internal errors):Motivation
Currently I was creating my own errors like so, but I would like to leverage Fastify sensible in the
onSend
instead of reinventing the wheel here:Example
Code that cause the error:
The text was updated successfully, but these errors were encountered: