mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat/fix: add DiscordAPIError#path and fixed Burst request handler handling api errors (#1867)
This commit is contained in:
@@ -3,12 +3,18 @@
|
|||||||
* @extends Error
|
* @extends Error
|
||||||
*/
|
*/
|
||||||
class DiscordAPIError extends Error {
|
class DiscordAPIError extends Error {
|
||||||
constructor(error) {
|
constructor(path, error) {
|
||||||
super();
|
super();
|
||||||
const flattened = this.constructor.flattenErrors(error.errors || error).join('\n');
|
const flattened = this.constructor.flattenErrors(error.errors || error).join('\n');
|
||||||
this.name = 'DiscordAPIError';
|
this.name = 'DiscordAPIError';
|
||||||
this.message = error.message && flattened ? `${error.message}\n${flattened}` : error.message || flattened;
|
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
|
* HTTP error code returned by Discord
|
||||||
* @type {number}
|
* @type {number}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class BurstRequestHandler extends RequestHandler {
|
|||||||
this.resetTimeout = null;
|
this.resetTimeout = null;
|
||||||
}, 1e3 + this.client.options.restTimeOffset);
|
}, 1e3 + this.client.options.restTimeOffset);
|
||||||
} else {
|
} 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();
|
this.handle();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class SequentialRequestHandler extends RequestHandler {
|
|||||||
this.queue.unshift(item);
|
this.queue.unshift(item);
|
||||||
this.restManager.client.setTimeout(resolve, 1e3 + this.client.options.restTimeOffset);
|
this.restManager.client.setTimeout(resolve, 1e3 + this.client.options.restTimeOffset);
|
||||||
} else {
|
} 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);
|
resolve(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user