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

res.status is not a function #1

Open
santhoshdasari786 opened this issue Jul 25, 2018 · 13 comments
Open

res.status is not a function #1

santhoshdasari786 opened this issue Jul 25, 2018 · 13 comments

Comments

@santhoshdasari786
Copy link

i am getting this issue

@kadko
Copy link

kadko commented Aug 8, 2018

Error handling use middleware must be 4 parameter not 3. Actually res.status becoming as next.status so next has no status function

The default error handler chapter: https://expressjs.com/en/guide/error-handling.html

app.use((err, req, res) => {
Change to :

app.use((err, req, res, next) {

@jeremyb20
Copy link

Try this code if it works

app.use(function (err, req, res, next) {
res.status(err.status || 500);

res.json({
  errors: {
    message: err.message,
    error: err,
  },
});

})
}

app.use(function(err, req, res, next) {
res.status(err.status || 500);

res.json({
errors: {
message: err.message,
error: {},
},
});
});

@santhoshdasari786
Copy link
Author

santhoshdasari786 commented Oct 4, 2018 via email

@llermaly
Copy link

hey @DarveshHere I'm having this error :

{
"errors": {
"message": "Cannot read property 'email' of undefined",
"error": {}
}
}

when trying to POST a user , could you help me please?

regards

@santhoshdasari786
Copy link
Author

santhoshdasari786 commented Oct 31, 2018 via email

@Dyon42
Copy link

Dyon42 commented Nov 7, 2018

i get a POST /users 404 0.404 ms - 145 can someone help me ? it appears after i changed the extra next argument

@Dyon42
Copy link

Dyon42 commented Nov 7, 2018

please fix this code correct i want to learn from this code :)

@dlpazs
Copy link

dlpazs commented Jan 22, 2019

Make sure your POSTMAN GET request has Headers; Key:Token and Content-type:application/json. If your getting the Email of undefined your POST request in POSTMAN is missing content-type:application/json.

@daryl-williams
Copy link

daryl-williams commented Apr 4, 2019

I am getting the same error: res.status is not a function
and have changed the code as suggested:

app.use(function(err, req, res, next) {
  res.status(err.status || 500);
    res.json({
      errors: {
        message: err.message,
        error: err,
      },
    });
  });
}

but continue to get the same error. Is there a working example of this code anywhere?
Would love to continue learning passport, et.al.

Regards,

Daryl

@justraman
Copy link

replace line ** return status(400).info**
with
return res.status(400).send(info);

@williehallock802
Copy link

I too am experiencing a problems related to this bug and the suggested fixes are not quite working for me.

On, lines 41 & 53 in app.js, I have:

app.use((err, req, res, next)

and on line 67 in users.js, I have:

return res.status(400).send( info );

however, when I start and visit http://localhost:8000/, I get the message in the browser:

Cannot GET /

@chaimite
Copy link

I am getting the same problem as @williehallock802

@doshik
Copy link

doshik commented Mar 24, 2021

I have the same error as above ^

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