axa-group / bauta.js

Bauta.js is an add-on for your Node.js applications such as Express.js or Fastify.
Other
42 stars 3 forks source link

bautajs-fastify: remove deprecated fastify reply.sent #127

Closed rodrigo1991 closed 11 months ago

rodrigo1991 commented 11 months ago

in file packages/bautajs-fastify/src/expose-routes.ts on line 49 there is a deprecated code that fastify suggest to remove "FastifyDeprecation: Modifying the "reply.sent" property is deprecated. Use the "reply.hijack()" method instead."

Screenshot 2023-12-14 at 12 19 19

Besides we're "duplicating" the intended behavior by already using reply.hijack(); in the line 47. Also using reply.sent leads to an error instead of avoiding re-sending the response (fastify/lib/reply:107): note that at this point, reply.hijack(); has already set the value this[kReplyHijacked]to true so the if at line 106 will always be true and will throw the error

Screenshot 2023-12-14 at 12 23 35
ERROR (95356): Response has been sent to the requester, but the promise threw an error
    reqId: "req-1"
    error: {
      "name": "FastifyError",
      "code": "FST_ERR_REP_ALREADY_SENT",
      "message": "Reply was already sent, did you forget to \"return reply\" in \"/v1/conversations\" (POST)?"
    }
ERROR (95356): Promise errored, but reply.sent = true was set
    reqId: "req-1"
    err: {
      "type": "FastifyError",
      "message": "Reply was already sent, did you forget to \"return reply\" in \"/v1/conversations\" (POST)?",
      "stack":
          FastifyError: Reply was already sent, did you forget to "return reply" in "/v1/conversations" (POST)?
              at _Reply.set [as sent] (/Users/rodrigor/Documents/secure-gpt/node_modules/fastify/lib/reply.js:107:15)
              at Object.<anonymous> (/Users/rodrigor/Documents/secure-gpt/node_modules/@axa/bautajs-fastify/src/expose-routes.ts:101:19)
              at processTicksAndRejections (node:internal/process/task_queues:95:5)
      "code": "FST_ERR_REP_ALREADY_SENT",
      "name": "FastifyError",
      "statusCode": 500
    }
franher commented 11 months ago

thank you @rodrigo1991 for the issue :)