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:

    1. └─▶ schemaErrorFormatter
    2. reply sent ◀── JSON ─┴─ Error instance
    3. throw an Error
    4. send or return
    5. reply sent ◀── JSON ─┴─ Error instance ──▶ setErrorHandler ◀─────┘
    6. reply sent ◀── JSON ─┴─ Error instance ──▶ onError Hook
    7. └─▶ reply sent
    • the if set
    • or by the default JSON.stringify function