dadi / passport

A library for generating access tokens to authenticate with DADI platform components
7 stars 3 forks source link

Error responses #7

Closed jimlambie closed 8 years ago

jimlambie commented 8 years ago

We have at least two error cases to handle, to match the existing auth token request in Web:

  1. an invalid set of credentials
  2. failed token request, due to incorrect uri or general network error

Currently in Web these are handled as follows:

  1. Invalid Credentials
var err = new Error('Authentication');
err.message = 'No token received, invalid credentials.';
err.remoteIp = options.hostname;
err.remotePort = options.port;
err.path = options.path;
  1. Invalid URI / network error
var err = new Error('Authentication');
err.message = "Couldn't request accessToken";
err.remoteIp = options.hostname;
err.remotePort = options.port;
err.path = options.path;

Currently in Passport I get an unhandled exception response if the credentials are incorrect. In some of the other apps we've started to use the JSON API spec for errors. Could we look at returning an errors collection in passport also?

For example:

{
  "errors": [
    {
      "status": "Not Found",
      "code": "",
      "title": "URL Not Found",
      "details": "The request for URL '<url>' returned a 404."
    }
  ]
}
eduardoboucas commented 8 years ago

Following convo on Slack, I'll make the Promise reject when any of those errors occur.

eduardoboucas commented 8 years ago

Closing, as this was added in #9.