HTTP Status bug
Getting a weird bug when returning a response in my project for a
post
request.
Previous get
requests return data correctly, but this one is giving me problems for some obscure reason.
This results in an Internal server error
Error message:
The status provided (0) must be 101 or in the range of [200, 599]
13 Replies
Route handler:
I added the early return JSON for testing purposes, but the same result occurs
what is the value of
HttpStatusCode.OK_200
?200
replaced with an enum to not use magic numbers
I will send a middleware that is also used, but no status is being set
magic numbers?
http status codes definitely aren't magic numbers
the error message is telling you that Bun is getting
0
instead of 200
for the status, so i'd start by replacing the enums with integers, at least to debug
hono only lets you use valid status codes with the response helpers (like c.json
), so it's totally type-safeIt's a lint rule I have set up for my code base, yeah status codes are protocol level so everyone should know them, but for juniors that might be looking at the codebase that might not be the case
this is a middleware that I'm using before the request
I'm running
hono@^4.8.5
, the zod validator shouldn't be the problem as the request enters the if statement
reverted my tsconfig to something simpler, but no improvements

it's a runtime error, not a typescript issue
try replacing the status code enums with integer values
I know, thought maybe the bunde/module affected honos esm/module imports, but that likely isnt the case as it's bundled code
unless you're overriding the status code somewhere else, the enums seem like they could be the issue
this is the code that ran for the screenshot

I introduced the enum after the bug started occurring as I thought I was crazy
the get requests in the router with the same
200
number where doing OK, but the post request wasn't
the exception is occurring before my console.logs
ok I figured it out
the provideAuction
middleware didn't return the next()
result
sorry @ambergristle for the hassleno worries; happy to help!
how do I mark this as solved now?
found it