From 54a5c38b66d759450072331fa226c42308db901b Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 29 Jul 2015 10:30:07 +0100 Subject: [PATCH] Do not retry requests which 40[0/1/3]. Set 'errcode' on MatrixErrors --- lib/http-api.js | 4 +++- lib/scheduler.js | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/http-api.js b/lib/http-api.js index bb425c3f2..987caafd3 100644 --- a/lib/http-api.js +++ b/lib/http-api.js @@ -422,12 +422,14 @@ var requestCallback = function(defer, userDefinedCallback, onlyData) { * information specific to the standard Matrix error response. * @constructor * @param {Object} errorJson The Matrix error JSON returned from the homeserver. - * @prop {string} name The Matrix 'errcode' value, e.g. "M_FORBIDDEN". + * @prop {string} errcode The Matrix 'errcode' value, e.g. "M_FORBIDDEN". + * @prop {string} name Same as MatrixError.errcode but with a default unknown string. * @prop {string} message The Matrix 'error' value, e.g. "Missing token." * @prop {Object} data The raw Matrix error JSON used to construct this object. * @prop {integer} httpStatus The numeric HTTP status code given */ module.exports.MatrixError = function MatrixError(errorJson) { + this.errcode = errorJson.errcode; this.name = errorJson.errcode || "Unknown error code"; this.message = errorJson.error || "Unknown message"; this.data = errorJson; diff --git a/lib/scheduler.js b/lib/scheduler.js index 46ddc9f6a..e78e5dfe3 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -129,6 +129,10 @@ MatrixScheduler.prototype.queueEvent = function(event) { * @see module:scheduler~retryAlgorithm */ MatrixScheduler.RETRY_BACKOFF_RATELIMIT = function(event, attempts, err) { + if (err.httpStatus === 400 || err.httpStatus === 403 || err.httpStatus === 401) { + // client error; no amount of retrying with save you now. + return -1; + } if (err.name === "M_LIMIT_EXCEEDED") { var waitTime = err.data.retry_after_ms; if (waitTime) {