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

Error handling #11

Open
lludol opened this issue Apr 13, 2016 · 2 comments
Open

Error handling #11

lludol opened this issue Apr 13, 2016 · 2 comments

Comments

@lludol
Copy link

lludol commented Apr 13, 2016

Hello,

In the doc of your plugin, it's written that we can add our custom logic to manage unauthorized access.

With this code:

app.use(function (err, req, res, next) {
  if (err.name === 'UnauthorizedError') {
    res.send(401, 'invalid token...');
  }
});

But, if we read the doc of restify, the callback will receive only 3 parameters : req, res and next.
(source: http://restify.com/#common-handlers-serveruse)
I have tested with 4 parameters but the function only receive 3 parameters...

In my application, I am using your module only for route that need to be protected, like this:

app.get('/example/:id', jwt({ secret: mySecret }) , (req, res) => { /* the code of the route */ });

Did I miss something?

@lludol
Copy link
Author

lludol commented Sep 3, 2016

I have found a solution:

server.on('InvalidCredentials', (req, res, error, next) => {
  error.body.code = 'Unauthorized';
  error.body.message = 'Your custom message';
  return next();
});

I don't think this is the best solution but it works...

@pkid169
Copy link

pkid169 commented Apr 24, 2017

@lludol @amrav Can we PR this (provided the above is the appropriate solution)?

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