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