Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exports.config = require('./lib/config');
exports.Client = require('./lib/client');
exports.Dispatcher = require('./lib/dispatcher');
exports.auth = require('./lib/auth');
Expand Down
9 changes: 9 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var errors = require('../errors');

var config = {};

config.setConfig = function(errorName, errorConfig) {
errors[errorName].config = errorConfig;
};

module.exports = config;
26 changes: 10 additions & 16 deletions lib/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@ var querystring = require('querystring');

var VERSION = require('../package.json').version;

var STATUS_MAP = null;

setTimeout(function() {
STATUS_MAP = Object.keys(errors).reduce(function(map, key) {
if (key === 'config') {
return map;
}
var args = errors.config[key];
var error = new errors[key](args);
if (error.status) {
map[error.status] = errors[key];
}
return map;
}, {});
}, 0);
var STATUS_MAP = Object.keys(errors).reduce(function(map, key) {
var error = new errors[key](null);
if (error.status) {
map[error.status] = errors[key];
}
return map;
}, {});

// TODO: Provide same set of options for each request as for configuration,
// so the config at construction time is just the "defaults"
Expand Down Expand Up @@ -166,7 +158,9 @@ Dispatcher.prototype.dispatch = function(params, dispatchOptions) {
return reject(err);
}
if (STATUS_MAP[res.statusCode]) {
var error = new STATUS_MAP[res.statusCode](payload);
var errorConfig = STATUS_MAP[res.statusCode].config;
var args = Object.assign(payload, errorConfig);
var error = new STATUS_MAP[res.statusCode](args);

if (me.retryOnRateLimit &&
error instanceof (errors.RateLimitEnforced)) {
Expand Down
26 changes: 0 additions & 26 deletions lib/errors/config.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/errors/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
exports.config = require('./config');

exports.Forbidden = require('./forbidden');
exports.InvalidRequest = require('./invalid_request');
exports.NoAuthorization = require('./no_authorization');
Expand Down
3 changes: 1 addition & 2 deletions lib/errors/rate_limit_enforced.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ function RateLimitEnforced(value) {
AsanaError.call(this, 'Rate Limit Enforced');
this.status = 429;
this.value = value;

this.retryAfterSeconds = value && parseInt(value.retry_after, 10);
}

util.inherits(RateLimitEnforced, Error);

module.exports = RateLimitEnforced;
module.exports = RateLimitEnforced;
3 changes: 0 additions & 3 deletions test/dispatcher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ describe('Dispatcher', function() {
});

Object.keys(errors).forEach(function(key) {
if (key === 'config') {
return;
}
it('should create an error for ' + key, function() {
var request = sinon.stub();
var err = new errors[key]();
Expand Down