diff options
author | Puyodead1 <puyodead@proton.me> | 2022-12-24 16:24:58 -0500 |
---|---|---|
committer | Puyodead1 <puyodead@proton.me> | 2023-03-18 19:28:45 -0400 |
commit | 6d6944cfee4af656c6386c7a44efc6b99bdfd6ed (patch) | |
tree | 72ed39ba329e7cbd894ddcc0fabdcbdf636ef4a6 /src/connections/EpicGames/index.ts | |
parent | Fix connection update visibilty dying when given boolean (diff) | |
download | server-6d6944cfee4af656c6386c7a44efc6b99bdfd6ed.tar.xz |
Add Twitch, error handling, revokation changes, etc
Diffstat (limited to 'src/connections/EpicGames/index.ts')
-rw-r--r-- | src/connections/EpicGames/index.ts | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/connections/EpicGames/index.ts b/src/connections/EpicGames/index.ts index f1f3f24c..c720dc5d 100644 --- a/src/connections/EpicGames/index.ts +++ b/src/connections/EpicGames/index.ts @@ -1,4 +1,5 @@ import { + ApiError, Config, ConnectedAccount, ConnectedAccountCommonOAuthTokenResponse, @@ -86,12 +87,18 @@ export default class EpicGamesConnection extends Connection { code, }), }) - .then((res) => res.json()) + .then((res) => { + if (!res.ok) { + throw new ApiError("Failed to exchange code", 0, 400); + } + + return res.json(); + }) .catch((e) => { console.error( `Error exchanging token for ${this.id} connection: ${e}`, ); - throw DiscordApiErrors.INVALID_OAUTH_TOKEN; + throw DiscordApiErrors.GENERAL_ERROR; }); } @@ -106,7 +113,20 @@ export default class EpicGamesConnection extends Connection { headers: { Authorization: `Bearer ${token}`, }, - }).then((res) => res.json()); + }) + .then((res) => { + if (!res.ok) { + throw new ApiError("Failed to fetch user", 0, 400); + } + + return res.json(); + }) + .catch((e) => { + console.error( + `Error fetching user for ${this.id} connection: ${e}`, + ); + throw DiscordApiErrors.GENERAL_ERROR; + }); } async handleCallback( |