-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default response status code should be set at the end #1326
Comments
You can make a PR if you want, but I'm afraid this might heavily break applications relying on current behaviour. |
It can be implemented as a form of app-wide option for compatibility. but I'm not sure if it can be approved because there is no app-wide option in Koa for now. And I found out a workaround can solve my case by just adding a middleware at the first which is set status to undefined.. so this issue is not urgent but IMHO it should be default behavior in the next major version. |
This doesn't work anymore because of this code in response.js assert(Number.isInteger(code), 'status code must be a number');
assert(code >= 100 && code <= 999, `invalid status code: ${code}`); |
@turbobuilt I think we should be able to distinguish whether status is default at least for now. This is quite important issue. I'll try to make PR soon. |
Ah, good idea. I think that it is very important as well for UX, because it really frustrated me getting 404s when I was starting simply because I didn't return any data. |
I stumbled upon this issue yesterday. some-file: // ...
context.throw([code], [message], { statusCode: [code] });
// ... on error: app.on('error', (error, context) => {
// ...
if (error.statusCode >= 500) {
// ...
}
// ...
}); |
What's the use-case for this? If you didn't handle the response, then it should 404 |
please re-open with a use-case, closing to clean up the repo. thanks |
My suggestion:
Default response status code should be set at the end of response, not before route handlers run.
In my case, I'm trying to catch custom error object(Boom) thrown from handlers and set response status by error type at middlewares. But I always get default 404 unless res.body is set, and I don't know whether the 404 is set by default or my handlers or middlewares.
a known workaround does not work now.
The text was updated successfully, but these errors were encountered: