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

Check for invalid or unknown http status codes. #4598

Closed
wants to merge 1 commit into from
Closed

Check for invalid or unknown http status codes. #4598

wants to merge 1 commit into from

Conversation

AakifurRahman
Copy link

Nodejs http module does not throw any error for invalid ( undefined http response codes ) up to 999. Any typo ( like 209 instead of 208 [ Already Reported ] or 309 instead of 308 [ Permanent Redirect] ) might causes inconvenience at the frontend. An error message throw by express can prevent this.

Code:

const express = require("express");

const app = express();
const PORT = 8000

app.get("/", (req, res) => {
  res.status(209).json({
    data:"test"
  });
});

app.listen(PORT, () => {
  console.log("App is running");
});

Before change

Before

  1. The response data is passed.
  2. Postman marks the status code as unknown

After change

After

  1. A 500 - Internal Server Error is thrown
  2. A error message is displayed ( TypeError: 209 is not a valid http status code. )

@dougwilson
Copy link
Contributor

Duplicate of #4212

@dougwilson dougwilson marked this as a duplicate of #4212 May 23, 2021
@dougwilson dougwilson closed this May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants