Skip to content
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

response gives invalid status code when number is sent in res.status(200).send(<number>); #5446

Closed
bhavya3024 opened this issue Feb 6, 2024 · 4 comments

Comments

@bhavya3024
Copy link

bhavya3024 commented Feb 6, 2024

Hi there,

While I was testing my own PR, #5445, I encountered an other issue sending number to res.send(<number>),
I get the following error:

<html lang="en">  
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: 10<br> &nbsp; &nbsp;at ServerResponse.writeHead (node:_http_server:352:11)<br> &nbsp; &nbsp;at ServerResponse._implicitHeader (node:_http_server:338:8)<br> &nbsp; &nbsp;at ServerResponse.end (node:_http_outgoing:1046:10)<br> &nbsp; &nbsp;at ServerResponse.send (/home/bhavya/Documents/Sample/node_modules/express/lib/response.js:232:10)<br> &nbsp; &nbsp;at /home/bhavya/Documents/Sample/index.js:7:21<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/home/bhavya/Documents/Sample/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/home/bhavya/Documents/Sample/node_modules/express/lib/router/route.js:144:13)<br> &nbsp; &nbsp;at Route.dispatch (/home/bhavya/Documents/Sample/node_modules/express/lib/router/route.js:114:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/home/bhavya/Documents/Sample/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at /home/bhavya/Documents/Sample/node_modules/express/lib/router/index.js:284:15</pre>
</body>
</html>

Is this intentional, or it is a bug that needs to fixed ?
meanwhile, res.json(10) works fine.
@mikeal @peters @nick @mcolyer @kavu

@dougwilson
Copy link
Contributor

It is not a bug. As per the documentation, if you provide a number to res.send it needs to be a valid staus code number, otherwise it is expecred you will get an error back that it is not a valid status code.

@dougwilson
Copy link
Contributor

We deprecated that behavior in 4.x and I think it may be removed in 5. Using res.sendStatus is the preferred method to send a status code number. This is in effort to reduce the number of overloads on res.send signature.

@bhavya3024
Copy link
Author

We deprecated that behavior in 4.x and I think it may be removed in 5. Using res.sendStatus is the preferred method to send a status code number. This is in effort to reduce the number of overloads on res.send signature.
@dougwilson anyways, when we are expecting a stable release of version 5 in express ?

@dougwilson
Copy link
Contributor

It is in the works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants