summary refs log tree commit diff
path: root/src/connections/BattleNet/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/connections/BattleNet/index.ts')
-rw-r--r--src/connections/BattleNet/index.ts25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/connections/BattleNet/index.ts b/src/connections/BattleNet/index.ts
index ecba0fa9..8e8eeeed 100644
--- a/src/connections/BattleNet/index.ts
+++ b/src/connections/BattleNet/index.ts
@@ -1,4 +1,5 @@
 import {
+	ApiError,
 	Config,
 	ConnectedAccount,
 	ConnectedAccountCommonOAuthTokenResponse,
@@ -81,7 +82,13 @@ export default class BattleNetConnection extends Connection {
 				}/connections/${this.id}/callback`,
 			}),
 		})
-			.then((res) => res.json())
+			.then((res) => {
+				if (!res.ok) {
+					throw new ApiError("Failed to exchange code", 0, 400);
+				}
+
+				return res.json();
+			})
 			.then(
 				(
 					res: ConnectedAccountCommonOAuthTokenResponse &
@@ -95,7 +102,7 @@ export default class BattleNetConnection extends Connection {
 				console.error(
 					`Error exchanging token for ${this.id} connection: ${e}`,
 				);
-				throw DiscordApiErrors.INVALID_OAUTH_TOKEN;
+				throw DiscordApiErrors.GENERAL_ERROR;
 			});
 	}
 
@@ -107,10 +114,22 @@ export default class BattleNetConnection extends Connection {
 				Authorization: `Bearer ${token}`,
 			},
 		})
-			.then((res) => res.json())
+			.then((res) => {
+				if (!res.ok) {
+					throw new ApiError("Failed to fetch user", 0, 400);
+				}
+
+				return res.json();
+			})
 			.then((res: BattleNetConnectionUser & BattleNetErrorResponse) => {
 				if (res.error) throw new Error(res.error_description);
 				return res;
+			})
+			.catch((e) => {
+				console.error(
+					`Error fetching user for ${this.id} connection: ${e}`,
+				);
+				throw DiscordApiErrors.GENERAL_ERROR;
 			});
 	}