11/* eslint-disable no-restricted-syntax */
22import axios , { AxiosError , AxiosInstance } from 'axios' ;
33import rateLimit , { RateLimitedAxiosInstance } from 'axios-rate-limit' ;
4- import { URLSearchParams } from 'url' ;
54import { version } from '../../package.json' ;
65import Client from '../client/Client' ;
76import FortniteAPIError from '../exceptions/FortniteAPIError' ;
87import InvalidAPIKeyError from '../exceptions/InvalidAPIKeyError' ;
98import MissingAPIKeyError from '../exceptions/MissingAPIKeyError' ;
9+ import { serializeParams } from '../util/util' ;
1010import { FortniteAPIResponseData } from './httpStructs' ;
1111
1212class HTTP {
@@ -29,27 +29,18 @@ class HTTP {
2929 } ,
3030 } ) ;
3131
32- this . statsAxios = rateLimit ( this . axios , { maxRequests : 3 , perMilliseconds : 1100 } ) ;
32+ this . statsAxios = rateLimit ( this . axios , {
33+ maxRequests : 3 ,
34+ perMilliseconds : 1100 + this . client . config . rateLimitExtraTimeout ,
35+ } ) ;
3336 }
3437
3538 public async fetch ( url : string , params ?: any ) : Promise < FortniteAPIResponseData > {
3639 try {
3740 const response = await this . axios ( {
3841 url,
3942 params,
40- paramsSerializer : ( p ) => {
41- const searchParams = new URLSearchParams ( ) ;
42-
43- for ( const [ key , value ] of Object . entries ( p ) ) {
44- if ( Array . isArray ( value ) ) {
45- for ( const singleValue of value ) searchParams . append ( key , singleValue ) ;
46- } else {
47- searchParams . append ( key , ( value as any ) ) ;
48- }
49- }
50-
51- return searchParams . toString ( ) ;
52- } ,
43+ paramsSerializer : serializeParams ,
5344 } ) ;
5445
5546 return response . data ;
@@ -72,22 +63,12 @@ class HTTP {
7263
7364 public async fetchStats ( url : string , params ?: any ) : Promise < FortniteAPIResponseData > {
7465 try {
75- const response = await this . statsAxios . get ( url , {
66+ const response = await this . statsAxios ( {
67+ url,
7668 params,
77- paramsSerializer : ( p ) => {
78- const searchParams = new URLSearchParams ( ) ;
79-
80- for ( const [ key , value ] of Object . entries ( p ) ) {
81- if ( Array . isArray ( value ) ) {
82- for ( const singleValue of value ) searchParams . append ( key , singleValue ) ;
83- } else {
84- searchParams . append ( key , ( value as any ) ) ;
85- }
86- }
87-
88- return searchParams . toString ( ) ;
89- } ,
69+ paramsSerializer : serializeParams ,
9070 } ) ;
71+
9172 return response . data ;
9273 } catch ( e ) {
9374 if ( e instanceof AxiosError && e . response ?. data ?. error ) {
0 commit comments