diff --git a/src/connections/GitHub/index.ts b/src/connections/GitHub/index.ts
index aa686b03..8380e765 100644
--- a/src/connections/GitHub/index.ts
+++ b/src/connections/GitHub/index.ts
@@ -1,5 +1,4 @@
import {
- ApiError,
Config,
ConnectedAccount,
ConnectedAccountCommonOAuthTokenResponse,
@@ -7,7 +6,7 @@ import {
ConnectionLoader,
DiscordApiErrors,
} from "@fosscord/util";
-import fetch from "node-fetch";
+import wretch from "wretch";
import Connection from "../../util/connections/Connection";
import { GitHubSettings } from "./GitHubSettings";
@@ -65,46 +64,29 @@ export default class GitHubConnection extends Connection {
const url = this.getTokenUrl(code);
- return fetch(url.toString(), {
- method: "POST",
- headers: {
+ return wretch(url.toString())
+ .headers({
Accept: "application/json",
- },
- })
- .then((res) => {
- if (!res.ok) {
- throw new ApiError("Failed to exchange code", 0, 400);
- }
-
- return res.json();
})
+
+ .post()
+ .json<ConnectedAccountCommonOAuthTokenResponse>()
.catch((e) => {
- console.error(
- `Error exchanging code for ${this.id} connection: ${e}`,
- );
+ console.error(e);
throw DiscordApiErrors.GENERAL_ERROR;
});
}
async getUser(token: string): Promise<UserResponse> {
const url = new URL(this.userInfoUrl);
- return fetch(url.toString(), {
- method: "GET",
- headers: {
+ return wretch(url.toString())
+ .headers({
Authorization: `Bearer ${token}`,
- },
- })
- .then((res) => {
- if (!res.ok) {
- throw new ApiError("Failed to fetch user", 0, 400);
- }
-
- return res.json();
})
+ .get()
+ .json<UserResponse>()
.catch((e) => {
- console.error(
- `Error fetching user for ${this.id} connection: ${e}`,
- );
+ console.error(e);
throw DiscordApiErrors.GENERAL_ERROR;
});
}
|