Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Rest): optional ratelimit errors (#5659)
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
- Loading branch information
1 parent
c2b3ed0
commit 16f261e
Showing
6 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Represents a RateLimit error from a request. | ||
* @extends Error | ||
*/ | ||
class RateLimitError extends Error { | ||
constructor({ timeout, limit, method, path, route, global }) { | ||
super(`A ${global ? 'global ' : ''}rate limit was hit on route ${route}`); | ||
|
||
/** | ||
* The name of the error | ||
* @type {string} | ||
*/ | ||
this.name = 'RateLimitError'; | ||
|
||
/** | ||
* Time until this rate limit ends, in ms | ||
* @type {number} | ||
*/ | ||
this.timeout = timeout; | ||
|
||
/** | ||
* The HTTP method used for the request | ||
* @type {string} | ||
*/ | ||
this.method = method; | ||
|
||
/** | ||
* The path of the request relative to the HTTP endpoint | ||
* @type {string} | ||
*/ | ||
this.path = path; | ||
|
||
/** | ||
* The route of the request relative to the HTTP endpoint | ||
* @type {string} | ||
*/ | ||
this.route = route; | ||
|
||
/** | ||
* Whether this rate limit is global | ||
* @type {boolean} | ||
*/ | ||
this.global = global; | ||
|
||
/** | ||
* The maximum amount of requests of this end point | ||
* @type {number} | ||
*/ | ||
this.limit = limit; | ||
} | ||
} | ||
|
||
module.exports = RateLimitError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters