passport-tutorial icon indicating copy to clipboard operation
passport-tutorial copied to clipboard

res.status is not a function

Open santhoshdasari786 opened this issue 6 years ago • 13 comments

i am getting this issue

santhoshdasari786 avatar Jul 25 '18 12:07 santhoshdasari786

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) {

kadko avatar Aug 08 '18 15:08 kadko

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: {}, }, }); });

jeremyb20 avatar Oct 03 '18 20:10 jeremyb20

Hi, Solved that issue. by adding extra params

On Thu, Oct 4, 2018 at 1:56 AM Jeremy Bacca Barquero < [email protected]> wrote:

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: {}, }, }); });

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AntonioErdeljac/passport-tutorial/issues/1#issuecomment-426788840, or mute the thread https://github.com/notifications/unsubscribe-auth/AdOtOJCm6fuwAdnwZ6eNMP5ti-FMdodXks5uhR1fgaJpZM4VgAQ- .

santhoshdasari786 avatar Oct 04 '18 16:10 santhoshdasari786

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

llermaly avatar Oct 31 '18 15:10 llermaly

Hi Darvesh, Kindly send this payload from the front end or postman . { email: "[email protected]", password:"xxxx"}

Note:- POST request with body containing keys email and password.

On Wed, Oct 31, 2018 at 8:48 PM llermaly [email protected] wrote:

hey @DarveshHere https://github.com/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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AntonioErdeljac/passport-tutorial/issues/1#issuecomment-434725979, or mute the thread https://github.com/notifications/unsubscribe-auth/AdOtOF9L7pVLZ3witeIbNZQxxoacTY9Sks5uqb84gaJpZM4VgAQ- .

santhoshdasari786 avatar Oct 31 '18 16:10 santhoshdasari786

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

Dyon42 avatar Nov 07 '18 01:11 Dyon42

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

Dyon42 avatar Nov 07 '18 01:11 Dyon42

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.

dlpazs avatar Jan 22 '19 17:01 dlpazs

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

daryl-williams avatar Apr 04 '19 22:04 daryl-williams

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

justraman avatar Apr 16 '19 12:04 justraman

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 /

williehallock802 avatar Nov 25 '19 16:11 williehallock802

I am getting the same problem as @williehallock802

chaimite avatar Nov 28 '19 22:11 chaimite

I have the same error as above ^

doshik avatar Mar 24 '21 05:03 doshik