You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Hono's middlewares, such as csrf, throw HTTPException by default. However, there is no simple way to customize this behavior to throw a specific application-layer exception.
To achieve this, developers need to wrap the middleware with a try-catch block and rethrow a custom exception, as shown below:
If an exception is provided, the middleware throws that instead of the default HTTPException. The original exception could be preserved in the cause property for debugging purposes.
Benefits
Reduces boilerplate code.
Maintains backward compatibility by defaulting to HTTPException.
The text was updated successfully, but these errors were encountered:
What is the feature you are proposing?
Description
Currently, Hono's middlewares, such as
csrf
, throwHTTPException
by default. However, there is no simple way to customize this behavior to throw a specific application-layer exception.To achieve this, developers need to wrap the middleware with a try-catch block and rethrow a custom exception, as shown below:
While this works, it introduces unnecessary boilerplate code.
Proposed Change
Add an optional exception property to specify a custom exception class:
If an exception is provided, the middleware throws that instead of the default
HTTPException
. The original exception could be preserved in thecause
property for debugging purposes.Benefits
HTTPException
.The text was updated successfully, but these errors were encountered: