Skip to content

Commit eac320e

Browse files
Merge pull request #10 from Polytoria/fetch-migration
Migrate from axios to fetch
2 parents 1cb6721 + cdb2011 commit eac320e

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
run: npm install
2020

2121
- name: Pull latest changes
22+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
2223
run: git pull
2324

2425
- name: Test build

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"dependencies": {
3-
"axios": "^1.7.3",
4-
"chalk": "^5.3.0",
3+
"chalk": "^5.4.1",
54
"discord-command-parser": "^1.5.3",
6-
"discord.js": "^14.16.2",
7-
"dotenv": "^16.4.5",
8-
"firebase-admin": "^12.3.1",
5+
"discord.js": "^14.17.3",
6+
"dotenv": "^16.4.7",
7+
"firebase-admin": "^13.0.2",
98
"parse-string-boolean": "^1.0.1",
109
"path": "^0.12.7",
1110
"to-boolean": "^1.0.0",
12-
"typescript": "^5.5.4"
11+
"typescript": "^5.7.2"
1312
},
1413
"name": "poly-verify",
1514
"description": "Polytoria Community Verify",

src/utils/polyUtils.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import axios from 'axios';
2-
31
/**
42
* polyUtils
53
*
@@ -16,19 +14,22 @@ export default class polyUtils {
1614
* @return {Promise<any>} User info
1715
*/
1816
public static async getUserInfoFromUsername(username: string): Promise<any> {
19-
const response = await axios.get(`https://api.polytoria.com/v1/users/find?username=${username}`, {
20-
validateStatus: () => true,
21-
});
17+
const response = await fetch(`https://api.polytoria.com/v1/users/find?username=${username}`);
18+
19+
if (!response.ok) {
20+
throw new Error(`Failed to fetch user info for username: ${username}`);
21+
}
2222

23-
// get id
24-
const data = response.data;
23+
const data = await response.json();
2524
const id = data.id;
2625

27-
const idResponse = await axios.get(`https://api.polytoria.com/v1/users/${id}`, {
28-
validateStatus: () => true,
29-
});
26+
const idResponse = await fetch(`https://api.polytoria.com/v1/users/${id}`);
3027

31-
const userData = idResponse.data;
28+
if (!idResponse.ok) {
29+
throw new Error(`Failed to fetch user info for ID: ${id}`);
30+
}
31+
32+
const userData = await idResponse.json();
3233

3334
return userData;
3435
}
@@ -42,11 +43,13 @@ export default class polyUtils {
4243
* @return {Promise<any>} User info
4344
*/
4445
public static async getUserInfoFromID(id: number): Promise<any> {
45-
const response = await axios.get(`https://api.polytoria.com/v1/users/${id}`, {
46-
validateStatus: () => true,
47-
});
46+
const response = await fetch(`https://api.polytoria.com/v1/users/${id}`);
47+
48+
if (!response.ok) {
49+
throw new Error(`Failed to fetch user info for ID: ${id}`);
50+
}
4851

49-
const userData = response.data;
52+
const userData = await response.json();
5053

5154
return userData;
5255
}

0 commit comments

Comments
 (0)