Middleware is not catching the error (Deno 2/Hono) #3497
cvermeer579
started this conversation in
General
Replies: 2 comments
-
you should use app.onError((err, c) => {
if (err instanceof HTTPException) {
// Get the custom response
console.log("HTTPException", err);
return err.getResponse();
}
if (err instanceof Error) {
// Get the custom response
console.log("Error", err);
return err.toString();
}
//...
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you, Dexus, for your guidance - it worked perfectly! I've attached the final source code for anyone who might face the same issue. TypeScript requires specific return types for error handling.
Thanks again for your prompt response! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear Hono Team,
I'm trying to implement a middleware to catch errors and log the error details, including the stack trace, to a file. However, I'm encountering an issue where the error is not caught in the middleware's catch block.
Below is a simplified version of my code:
When I call the /error route, I see the message "Entering try block" in the console, but the error is not being caught as expected, and "Error caught" is never logged.
I'm using Deno version 2.0.0-rc.10 and Hono version v4.3.11.
Is there something I might be missing in the error handling setup, or is this a known issue with Deno or Hono?
Thank you for your assistance!
Best regards,
Cornelis
Beta Was this translation helpful? Give feedback.
All reactions