reply.sent
A boolean indicating whether the response has already been sent.
Syntax
reply.sent Returns
boolean — true once the response has been dispatched.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.get('/race', async (_req, reply) => {
const timeout = setTimeout(() => {
if (!reply.sent) reply.code(504).send({ error: 'timeout' });
}, 5000);
try {
return await slowWork();
} finally {
clearTimeout(timeout);
}
});
Notes
Check reply.sent before sending again to avoid "reply already sent"
errors in race conditions such as timeouts. In modern Fastify prefer
returning values; sent is mainly for guarding manual send paths.