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

setting status code #4

Closed
sprzybylski opened this issue Jun 6, 2014 · 5 comments
Closed

setting status code #4

sprzybylski opened this issue Jun 6, 2014 · 5 comments
Labels

Comments

@sprzybylski
Copy link

Google APIs are returning error messages in following format:

{
  errors: [{
       domain: 'global',
       reason: 'authError',
       message: 'Invalid Credentials',
       locationType: 'header',
       location: 'Authorization'
  }],
  code: 401,
  message: 'Invalid Credentials'
}

statusCode is here under code property not status.

@defunctzombie
Copy link

What does this have to do with this module?

@sprzybylski
Copy link
Author

if (err.status) res.statusCode = err.status;

@dougwilson
Copy link
Contributor

This module only accepts Error objects of a specific format. Typically err.code is internal system codes like ENOENT in node.js land. This module will not cater to looking under the code property because it does not fit with the standards of the node.js ecosystem.

@sprzybylski
Copy link
Author

Ok, thanks.

@dougwilson
Copy link
Contributor

Your best bet if you want to use this module as your handler and throw those objects is to add a pre-processor before this module:

app.use(function(err,req,res,next){
  if (typeof err.code === 'number') {
    // copy Google API code to status property
    err.status = err.code;
  }
  next();
})
app.use(errorHandler())

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

No branches or pull requests

3 participants