dadi / passport

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

Add error responses #9

Closed eduardoboucas closed 8 years ago

eduardoboucas commented 8 years ago

This implements error responses as per #7. Errors that happen when requesting a new token will make the Promise reject, sending back an object following the JSON API format.

Example:

// `passport` was initialised with an incorrect URL
passport.then(function (bearer) {
    console.log('Bearer token: ' + bearer);
}).catch(function (error) {
    console.log(error);
});

Returns:

{ status: 'Not found',
  title: 'URL not found',
  detail: 'The request for URL \'http://fake-api.eb.dev.dadi.technology/token\' returned a 404.',
  code: '' }

So far it's forming proper error objects for 401 and 404 only, so I suppose the next step is to make it handle more types of error.

@jimlambie are you happy with this?

jimlambie commented 8 years ago

Looks execellent. Love the detail in your pull request also! On Sun, 21 Feb 2016 at 10:54, Eduardo Bouças notifications@github.com wrote:

This implements error responses as per #7 https://github.com/dadi/passport/issues/7. Errors that happen when requesting a new token will make the Promise reject, sending back an object following the JSON API format http://jsonapi.org/format/#errors.

Example:

// passport was initialised with an incorrect URLpassport.then(function (bearer) { console.log('Bearer token: ' + bearer); }).catch(function (error) { console.log(error); });

Returns:

{ status: 'Not found', title: 'URL not found', detail: 'The request for URL \'http://fake-api.eb.dev.dadi.technology/token\' returned a 404.', code: '' }

So far it's forming proper error objects for 401 and 404 only, so I suppose the next step is to make it handle more types of error.

@jimlambie https://github.com/jimlambie are you happy with this?

You can view, comment on, or merge this pull request online at:

https://github.com/dadi/passport/pull/9 Commit Summary

  • Add error handling

File Changes

Patch Links:

— Reply to this email directly or view it on GitHub https://github.com/dadi/passport/pull/9.

eduardoboucas commented 8 years ago

Great! Merging. (cc @josephdenne)