From 8b97ed34987908d38380586e77af393ece26a79c Mon Sep 17 00:00:00 2001 From: Trim21 Date: Wed, 28 Dec 2022 05:37:25 +0800 Subject: [PATCH 1/4] improve setErrorHandler example --- docs/Reference/Errors.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/Reference/Errors.md b/docs/Reference/Errors.md index 695c3ed171..d361a3efc7 100644 --- a/docs/Reference/Errors.md +++ b/docs/Reference/Errors.md @@ -112,7 +112,11 @@ fastify.setErrorHandler(function (error, request, reply) { this.log.error(error) // Send error response reply.status(500).send({ ok: false }) + return } + + // pop error to default error handler + return error }) // Run the server! @@ -382,4 +386,4 @@ Impossible to load plugin because the parent (mapped directly from `avvio`) #### FST_ERR_PLUGIN_TIMEOUT -Plugin did not start in time. Default timeout (in millis): `10000` \ No newline at end of file +Plugin did not start in time. Default timeout (in millis): `10000` From a7da345e61abf0b9ed7b2a3bd320b7f5d713238c Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 29 Dec 2022 19:44:28 +0800 Subject: [PATCH 2/4] Update Errors.md --- docs/Reference/Errors.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/Reference/Errors.md b/docs/Reference/Errors.md index d361a3efc7..d9b4cb8985 100644 --- a/docs/Reference/Errors.md +++ b/docs/Reference/Errors.md @@ -111,8 +111,7 @@ fastify.setErrorHandler(function (error, request, reply) { // Log error this.log.error(error) // Send error response - reply.status(500).send({ ok: false }) - return + return reply.status(500).send({ ok: false }) } // pop error to default error handler From a0ce58b8712010ab3ce7fcb847d7a875c7714a75 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 29 Dec 2022 21:35:03 +0800 Subject: [PATCH 3/4] review suggestion --- docs/Reference/Errors.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Reference/Errors.md b/docs/Reference/Errors.md index d9b4cb8985..6a96f3ede9 100644 --- a/docs/Reference/Errors.md +++ b/docs/Reference/Errors.md @@ -111,11 +111,11 @@ fastify.setErrorHandler(function (error, request, reply) { // Log error this.log.error(error) // Send error response - return reply.status(500).send({ ok: false }) + reply.status(500).send({ ok: false }) + } else { + // fastify will use parent error handler to handle this + reply.send(err) } - - // pop error to default error handler - return error }) // Run the server! From 77d7ccf52878a71cd72eff96e9c81dcd3f9d486d Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 29 Dec 2022 21:35:47 +0800 Subject: [PATCH 4/4] typo --- docs/Reference/Errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Reference/Errors.md b/docs/Reference/Errors.md index 6a96f3ede9..f925490ec5 100644 --- a/docs/Reference/Errors.md +++ b/docs/Reference/Errors.md @@ -114,7 +114,7 @@ fastify.setErrorHandler(function (error, request, reply) { reply.status(500).send({ ok: false }) } else { // fastify will use parent error handler to handle this - reply.send(err) + reply.send(error) } })