diff --git a/src/connections/Reddit/index.ts b/src/connections/Reddit/index.ts
index 182cd5a5..06fbcbe5 100644
--- a/src/connections/Reddit/index.ts
+++ b/src/connections/Reddit/index.ts
@@ -1,4 +1,5 @@
import {
+ ApiError,
Config,
ConnectedAccount,
ConnectedAccountCommonOAuthTokenResponse,
@@ -90,12 +91,18 @@ export default class RedditConnection extends Connection {
}/connections/${this.id}/callback`,
}),
})
- .then((res) => res.json())
+ .then((res) => {
+ if (!res.ok) {
+ throw new ApiError("Failed to code", 0, 400);
+ }
+
+ return res.json();
+ })
.catch((e) => {
console.error(
- `Error exchanging token for ${this.id} connection: ${e}`,
+ `Error exchanging code for ${this.id} connection: ${e}`,
);
- throw DiscordApiErrors.INVALID_OAUTH_TOKEN;
+ throw DiscordApiErrors.GENERAL_ERROR;
});
}
@@ -106,7 +113,20 @@ export default class RedditConnection 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(
|