🐛 Bug Report
When setting the response status code to undefined inside error handler, response returned is truncated.
This bug was unveiled while working on an issue with fastifh-gql default error handler, which set the response code to err.statusCode, that could be undefined.
To Reproduce
Codesandbox
Paste your code here:
const fastify = require("fastify");
const axios = require("axios");
async function start() {
const app = fastify({ logger: true });
app.setErrorHandler(async (err, request, reply) => {
reply.code(undefined);
return { errors: [err.message] };
});
app.get("/", async (request, reply) => {
throw new Error("This message will be truncated");
});
const port = 8080;
try {
await app.listen(port);
} catch (err) {
app.log.error(err);
process.exit(1);
}
await axios(`http://localhost:${port}`);
}
if (require.main === module) {
start();
}
You'll get in return:
(node:1727) UnhandledPromiseRejectionWarning: Error: Parse Error
at Socket.socketOnData (_http_client.js:442:20)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:287:12)
at readableAddChunk (_stream_readable.js:268:11)
at Socket.Readable.push (_stream_readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:94:17)
On a browser such as Firefox or Chrome, the response is truncated.
Expected behavior
The response should not be truncated.
Your Environment
- node version: 13.3
- fastify version: >=2.11.0
- os: Linux
🐛 Bug Report
When setting the response status code to
undefinedinside error handler, response returned is truncated.This bug was unveiled while working on an issue with
fastifh-gqldefault error handler, which set the response code toerr.statusCode, that could be undefined.To Reproduce
Codesandbox
Paste your code here:
You'll get in return:
On a browser such as Firefox or Chrome, the response is truncated.
Expected behavior
The response should not be truncated.
Your Environment