-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🦺 feat(core): add timeout to http client
- Loading branch information
1 parent
f139193
commit 84f43e2
Showing
2 changed files
with
78 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
export class DiscordAPIError extends Error {} | ||
export class DiscordAPIError extends Error { | ||
status: number; | ||
body: string; | ||
|
||
export class HTTPError extends Error {} | ||
constructor( | ||
status = 400, | ||
body: string, | ||
...params: ConstructorParameters<typeof Error> | ||
) { | ||
super(...params); | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, DiscordAPIError); | ||
} | ||
|
||
this.name = "DiscordAPIError"; | ||
this.status = status; | ||
this.body = body; | ||
} | ||
} | ||
|
||
export class DiscordAPIInternalError extends Error { | ||
status: number; | ||
|
||
constructor(status = 500, ...params: ConstructorParameters<typeof Error>) { | ||
super(...params); | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, DiscordAPIInternalError); | ||
} | ||
|
||
this.name = "DiscordAPIInternalError"; | ||
this.status = status; | ||
} | ||
} | ||
|
||
export class DiscordAPITimeoutError extends Error { | ||
timeout: number; | ||
|
||
constructor(timeout = 10000, ...params: ConstructorParameters<typeof Error>) { | ||
super(...params); | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, DiscordAPITimeoutError); | ||
} | ||
|
||
this.name = "DiscordAPITimeoutError"; | ||
this.timeout = timeout; | ||
} | ||
} |
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