Skip to content

Commit

Permalink
feat(DiscordAPIError): add method property (#2530)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored and SpaceEEC committed May 3, 2018
1 parent 17d2c2e commit 62605c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/rest/DiscordAPIError.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
* @extends Error
*/
class DiscordAPIError extends Error {
constructor(path, error) {
constructor(path, error, method) {
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 HTTP method used for the request
* @type {string}
*/
this.method = method;

/**
* The path of the request relative to the HTTP endpoint
* @type {string}
Expand Down
3 changes: 2 additions & 1 deletion src/rest/handlers/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class RequestHandler {
this.queue.unshift(item);
finish(1e3 + this.client.options.restTimeOffset);
} 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();
}
} else {
Expand Down

0 comments on commit 62605c4

Please sign in to comment.