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
import{HTTPException,Hono}from"hono";constapp=newHono();// Should throw 400, status is 200app.get("/example-a",(c)=>{thrownewHTTPException(400,{res: newResponse("An exception",{status: 200}),});});// Should throw 401, status is 200app.get("/example-b",(c)=>{thrownewHTTPException(401,{res: c.text("An exception"),});});// Correctly throws 401app.get("/example-c",(c)=>{thrownewHTTPException(401,{res: c.text("An exception",401),});});app.onError((err,c)=>{if(errinstanceofHTTPException){returnerr.getResponse();}console.error(`${err}`);returnc.text("Internal Server Error",500);});Deno.serve(app.fetch);
What is the expected behavior?
The behavior I expected is that the status provided to HTTPException would take precedent over response, especially if c.text(), c.json(), or c.html() are used, since those all set a 200 status by default.
What do you see instead?
The status of the response provided in the res argument always takes precedence.
Additional information
Unless this is intended behavior, I would propose HTTPException always return a response with the status code provided in the first argument.
Note: I did some cursory research into modifying the status of a Response instance. It appears modifying a Response status isn't possible, and clones of responses have read-only statuses as well. It would seem that implementing this change would necessitate creating a new Response, then applying the body and headers from the given Response, but ignoring the status and instead using the status given to HTTPException.
The text was updated successfully, but these errors were encountered:
Thank you for raising the issue. This should be fixed, OR we should find another way to add a Response object to HTTPException. I'll consider it. Please wait a bit!
What version of Hono are you using?
4.3.7
What runtime/platform is your app running on?
Deno
What steps can reproduce the bug?
What is the expected behavior?
The behavior I expected is that the status provided to
HTTPException
would take precedent over response, especially ifc.text()
,c.json()
, orc.html()
are used, since those all set a200
status by default.What do you see instead?
The status of the response provided in the
res
argument always takes precedence.Additional information
Unless this is intended behavior, I would propose
HTTPException
always return a response with the status code provided in the first argument.Note: I did some cursory research into modifying the status of a Response instance. It appears modifying a Response status isn't possible, and clones of responses have read-only statuses as well. It would seem that implementing this change would necessitate creating a new Response, then applying the body and headers from the given Response, but ignoring the status and instead using the status given to
HTTPException
.The text was updated successfully, but these errors were encountered: