Skip to content

Commit

Permalink
fix(typings): Fix http response typings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidffa committed Aug 3, 2023
1 parent 68fe88a commit 6ab05e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/sources/AppleMusic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ export default class AppleMusic extends AbstractExternalSource {
});

if (res.statusCode === 200) {
return res.body.json();
return res.body.json() as T;
} else {
return new AppleMusicError(await res.body.json());
return new AppleMusicError(await res.body.json() as IErrorResponse);
}
}

Expand Down
8 changes: 6 additions & 2 deletions lib/sources/Deezer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ export default class Deezer extends AbstractExternalSource {
}

private async makeRequest<T>(endpoint: string): Promise<T | DeezerError> {
const res = await request(`https://api.deezer.com/${endpoint}`).then(r => r.body.json());
const res = await request(`https://api.deezer.com/${endpoint}`).then(r => r.body.json()) as IDeezerResponse;

if (res.error) {
return new DeezerError(res.error.type, res.error.message);
}

return res;
return res as T;
}
}

Expand All @@ -116,6 +116,10 @@ class DeezerError implements IDeezerError {
}
}

interface IDeezerResponse {
error?: IDeezerError;
}

interface IDeezerError {
type: string;
message: string;
Expand Down
8 changes: 6 additions & 2 deletions lib/sources/Spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ export default class Spotify extends AbstractExternalSource {
headers: {
Authorization: this.token as string,
}
}).then(r => r.body.json());
}).then(r => r.body.json()) as ISpotifyResponse;

if (res.error) {
return new SpotifyError(res.error.message);
}

return res;
return res as T;
}

private async renewToken() {
Expand Down Expand Up @@ -266,6 +266,10 @@ class SpotifyError implements ISpotifyError {
}
}

interface ISpotifyResponse {
error?: ISpotifyError;
}

interface ISpotifyError {
message: string;
}
Expand Down

0 comments on commit 6ab05e5

Please sign in to comment.