From 95e22c2f12519fc6659c3f1664af11ff3175f7fe Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Fri, 1 Sep 2017 16:05:22 +0200 Subject: [PATCH] feat/fix: add DiscordAPIError#path and fixed Burst request handler handling api errors (#1867) --- src/client/rest/DiscordAPIError.js | 8 +++++++- src/client/rest/RequestHandlers/Burst.js | 2 +- src/client/rest/RequestHandlers/Sequential.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/client/rest/DiscordAPIError.js b/src/client/rest/DiscordAPIError.js index be1b82786..1b9c194d9 100644 --- a/src/client/rest/DiscordAPIError.js +++ b/src/client/rest/DiscordAPIError.js @@ -3,12 +3,18 @@ * @extends Error */ class DiscordAPIError extends Error { - constructor(error) { + constructor(path, error) { super(); const flattened = this.constructor.flattenErrors(error.errors || error).join('\n'); this.name = 'DiscordAPIError'; this.message = error.message && flattened ? `${error.message}\n${flattened}` : error.message || flattened; + /** + * The path of the request relative to the HTTP endpoint + * @type {string} + */ + this.path = path; + /** * HTTP error code returned by Discord * @type {number} diff --git a/src/client/rest/RequestHandlers/Burst.js b/src/client/rest/RequestHandlers/Burst.js index f3311ab65..1f941af31 100644 --- a/src/client/rest/RequestHandlers/Burst.js +++ b/src/client/rest/RequestHandlers/Burst.js @@ -47,7 +47,7 @@ class BurstRequestHandler extends RequestHandler { this.resetTimeout = null; }, 1e3 + this.client.options.restTimeOffset); } else { - item.reject(err.status === 400 ? new DiscordAPIError(res.body) : err); + item.reject(err.status >= 400 && err.status < 500 ? new DiscordAPIError(res.request.path, res.body) : err); this.handle(); } } else { diff --git a/src/client/rest/RequestHandlers/Sequential.js b/src/client/rest/RequestHandlers/Sequential.js index 42b07452e..5f026f7bb 100644 --- a/src/client/rest/RequestHandlers/Sequential.js +++ b/src/client/rest/RequestHandlers/Sequential.js @@ -68,7 +68,7 @@ class SequentialRequestHandler extends RequestHandler { this.queue.unshift(item); this.restManager.client.setTimeout(resolve, 1e3 + this.client.options.restTimeOffset); } else { - item.reject(err.status >= 400 && err.status < 500 ? new DiscordAPIError(res.body) : err); + item.reject(err.status >= 400 && err.status < 500 ? new DiscordAPIError(res.request.path, res.body) : err); resolve(err); } } else {