mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 17:52:55 +00:00
feat(DiscordAPIError): add method property (#2530)
This commit is contained in:
parent
17d2c2efb8
commit
62605c4470
2 changed files with 9 additions and 2 deletions
|
|
@ -3,12 +3,18 @@
|
||||||
* @extends Error
|
* @extends Error
|
||||||
*/
|
*/
|
||||||
class DiscordAPIError extends Error {
|
class DiscordAPIError extends Error {
|
||||||
constructor(path, error) {
|
constructor(path, error, method) {
|
||||||
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 HTTP method used for the request
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.method = method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path of the request relative to the HTTP endpoint
|
* The path of the request relative to the HTTP endpoint
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,8 @@ class RequestHandler {
|
||||||
this.queue.unshift(item);
|
this.queue.unshift(item);
|
||||||
finish(1e3 + this.client.options.restTimeOffset);
|
finish(1e3 + this.client.options.restTimeOffset);
|
||||||
} else {
|
} else {
|
||||||
item.reject(err.status >= 400 && err.status < 500 ? new DiscordAPIError(res.request.path, res.body) : err);
|
item.reject(err.status >= 400 && err.status < 500 ?
|
||||||
|
new DiscordAPIError(res.request.path, res.body, res.request.method) : err);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue