fix: improve error handling for iTunes API response and update cover not found response

This commit is contained in:
snusxd
2026-04-14 22:21:07 +03:00
parent 5730d6a5ac
commit 7134437e00
2 changed files with 10 additions and 4 deletions

View File

@@ -40,14 +40,20 @@ export async function itunes_cover_url(artist: string, album: string) {
.replace(/[-_,"':;|]/g, " ")
.toLowerCase();
const apple_music_results = await fetch("https://itunes.apple.com/search", {
const response = await fetch("https://itunes.apple.com/search", {
body: new URLSearchParams({
term: query,
entity: "song",
limit: "10",
}),
method: "POST",
}).then((res) => res.json());
});
if (!response.ok) {
throw new Error(`iTunes API failed with status ${response.status}`);
}
const apple_music_results = await response.json();
for (let result of apple_music_results.results) {
if (artist == result.artistName.toLowerCase()) {

View File

@@ -19,7 +19,7 @@ app.get("/cover/:artist/:album/:id", ({ params: { artist, album, id } }) =>
get_image_from_server(artist, album, id),
);
app.listen({ hostname: '0.0.0.0', port: 3000 }, ({ hostname, port }) => {
app.listen({ hostname: "0.0.0.0", port: 3000 }, ({ hostname, port }) => {
console.log(`🦊 Elysia is running at ${hostname}:${port}`);
});
@@ -74,7 +74,7 @@ async function get_image_from_server(
first_error,
secong_error,
);
throw Error("cover not found");
return new Response("Cover not found", { status: 404 });
}
}
}