Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close unused fetch responses #100

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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