Package Exports
- node-oauth-error
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-oauth-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-oauth-error
Convert oauth object-literal errors into actual Error() objects.
Why?
For some reason, the popular oauth module returns object literals instead of Error()
objects,
so this module simply converts oauth object-literal errors into actual Error()
objects. See oauth #250, #84, and #155.
Contribute
Please test this module in your projects and open issues or send pull requests if you would like to improve, extend or fix anything in this module. 😄
Install
Assuming you have oauth installed, now install node-oauth-error:
$ npm install --save node-oauth-error
Usage
const oauth = require('oauth');
const OAuthError = require('node-oauth-error');
oauth.get('some/url/endpoint',
credentials.accessToken,
credentials.accessTokenSecret,
(err, data) => {
if (err) {
// convert the oauth error into a real `Error()`.
throw new OAuthError(err);
}
// ...
}
);
Notes
This module knows how to convert oauth errors that have the following formats:
Format #1:
{
statusCode: 401,
data: '{"request": "\\/1.1\\/statuses\\/user_timeline.json", "error": "Not authorized."}'
}
Format #2:
{
statusCode: 401,
data: '{"errors": [{"code":89, "message": "Invalid or expired token."}]}'
}
If you see something I am missing, please open an issue or send a pull request. Thanks!
API
OAuthError(input)
The Error constructor.
input
Required
Type: object
The original oauth error object literal you want to convert to an actual Error.
License
MIT © Michael Wuergler