diff --git a/index.js b/index.js index 71fa4696..5ba21021 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +exports.config = require('./lib/config'); exports.Client = require('./lib/client'); exports.Dispatcher = require('./lib/dispatcher'); exports.auth = require('./lib/auth'); diff --git a/lib/config/index.js b/lib/config/index.js new file mode 100644 index 00000000..954514a6 --- /dev/null +++ b/lib/config/index.js @@ -0,0 +1,9 @@ +var errors = require('../errors'); + +var config = {}; + +config.setConfig = function(errorName, errorConfig) { + errors[errorName].config = errorConfig; +}; + +module.exports = config; diff --git a/lib/dispatcher.js b/lib/dispatcher.js index e999f082..7fbf371a 100644 --- a/lib/dispatcher.js +++ b/lib/dispatcher.js @@ -260,7 +260,9 @@ Dispatcher.prototype.dispatch = function(params, dispatchOptions) { } if (STATUS_MAP[res.statusCode]) { - var error = new STATUS_MAP[res.statusCode](payload, res); + var errorConfig = STATUS_MAP[res.statusCode].config; + var args = Object.assign({}, payload, errorConfig); + var error = new STATUS_MAP[res.statusCode](args, res); if (me.retryOnRateLimit && error instanceof (errors.RateLimitEnforced)) { diff --git a/lib/errors/rate_limit_enforced.js b/lib/errors/rate_limit_enforced.js index 4a759342..1a67f9f1 100644 --- a/lib/errors/rate_limit_enforced.js +++ b/lib/errors/rate_limit_enforced.js @@ -14,4 +14,4 @@ function RateLimitEnforced(value, res) { util.inherits(RateLimitEnforced, Error); -module.exports = RateLimitEnforced; \ No newline at end of file +module.exports = RateLimitEnforced;