On the right branch of every section there is the next phase of the lifecycle, on the left branch there is the corresponding error code that will be generated if the parent throws an error (note that all the errors are automatically handled by Fastify).
- Running all the following hooks and user handler
- Sending the response automatically
NB (*): If reply.raw
is used to send a response back to the user, onResponse
hooks will still be executed
Reply Lifecycle
- in async handler: it returns a payload
- in async handler: it throws an
Error
- in sync handler: it sends a payload
- in sync handler: it sends an
Error
instance
If the reply was hijacked, we skip all the below steps. Otherwise, when it is being submitted, the data flow performed is the following:
└─▶ schemaErrorFormatter
│
reply sent ◀── JSON ─┴─ Error instance
│
│ ★ throw an Error
★ send or return │ │
│ ▼ │
reply sent ◀── JSON ─┴─ Error instance ──▶ setErrorHandler ◀─────┘
│
reply sent ◀── JSON ─┴─ Error instance ──▶ onError Hook
│
└─▶ reply sent
- the if set
- or by the default
JSON.stringify
function