Hi,
this handle responses always empty body with 200 status code
fastify.get('/', async (req, reply) => {
reply.send({})
})
Maybe we need to figure out how to report (or throw an exception)
I lost 30minutes last time... 馃槩
Why it shouldn't?
In JavaScript if not specified every function return undefined at the end of its execution.
Since you are using async/await, this will be triggered and that's why you get an empty body.
I'm wondering why we are not throwing an exception in that case, since you are calling send two times (one with the implicit return and the one you written).
In this block https://github.com/fastify/fastify/blob/master/lib/reply.js#L29-L31, reply.sent聽is set to true after a setImmediate ends.
When returning a Promise, the promise is passed in https://github.com/fastify/fastify/blob/master/lib/handleRequest.js#L120. In https://github.com/fastify/fastify/blob/master/lib/reply.js#L76-L78 we handle that promise. As you can see in https://github.com/fastify/fastify/blob/master/lib/reply.js#L166, we are just calling reply.send()聽 with the payload.
All of this happens _asynchronously_, and the check in https://github.com/fastify/fastify/blob/master/lib/reply.js#L29-L31 is not triggered.
I will prepare a fix.
Most helpful comment
In this block https://github.com/fastify/fastify/blob/master/lib/reply.js#L29-L31,
reply.sent聽is set to true after asetImmediateends.When returning a Promise, the promise is passed in https://github.com/fastify/fastify/blob/master/lib/handleRequest.js#L120. In https://github.com/fastify/fastify/blob/master/lib/reply.js#L76-L78 we handle that promise. As you can see in https://github.com/fastify/fastify/blob/master/lib/reply.js#L166, we are just calling
reply.send()聽 with the payload.All of this happens _asynchronously_, and the check in https://github.com/fastify/fastify/blob/master/lib/reply.js#L29-L31 is not triggered.
I will prepare a fix.