Skip to content

Commit

Permalink
fix: close unused fetch responses
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Aug 29, 2024
1 parent c9dd1be commit 2b71a30
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions music-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main(rpc: Client) {
}
} catch (err) {
console.error("Error in main loop:", err);
await rpc.close(); // Ensure the connection is properly closed
rpc.close(); // Ensure the connection is properly closed

console.log("Attempting to reconnect...");
await sleep(DEFAULT_TIMEOUT); // wait before attempting to reconnect
Expand Down Expand Up @@ -113,7 +113,7 @@ async function _getTrackExtras(

if (!resp.ok) {
console.error("iTunes API error:", resp.statusText, url);

await resp.body?.cancel();
return {
artworkUrl: (await _getMBArtwork(artist, song, album)) ?? null,
iTunesUrl: null,
Expand Down Expand Up @@ -188,8 +188,10 @@ async function _getMBArtwork(

for (const release of json.releases) {
resp = await fetch(
`https://coverartarchive.org/release/${release.id}/front`
`https://coverartarchive.org/release/${release.id}/front`,
{ method: "HEAD" }
);
await resp.body?.cancel();
if (resp.ok) {
result = resp.url;
break;
Expand Down

0 comments on commit 2b71a30

Please sign in to comment.