Skip to content

Commit

Permalink
refactor(http): do not redefine static headers for each request
Browse files Browse the repository at this point in the history
  • Loading branch information
seth2810 committed Jul 29, 2024
1 parent 67cf5fe commit c4759a6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/http/HttpManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class HttpClient {
private createClient(): AxiosInstance {
const config: AxiosRequestConfig = {
proxy: this.config.http?.proxy,
headers: {
...this.config.http?.headers,
'User-Agent':
this.config.http?.userAgent ?? `@statsfm/spotify.js https://github.com/statsfm/spotify.js`
},
validateStatus: (status) => status >= 200 && status < 300
};

Expand Down Expand Up @@ -91,14 +96,11 @@ export class HttpClient {
const accessToken = await this.auth.getToken();

config.headers.Authorization = `Bearer ${accessToken}`;
config.headers['User-Agent'] =
this.config.http?.userAgent ?? `@statsfm/spotify.js https://github.com/statsfm/spotify.js`;
config.headers = Object.assign(this.config.http?.headers ?? {}, config.headers);

return config;
});

// attach error handling interceptor
// error handling interceptor
client.interceptors.response.use(
(response) => response,
(err: unknown) => this.handleError(client, err)
Expand Down

0 comments on commit c4759a6

Please sign in to comment.