Skip to content

Commit

Permalink
Stop logging Genius 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvollebregt committed May 18, 2024
1 parent 4204d41 commit 0b0075e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/api/genius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ export const getLyricsForPath = async (geniusPath: string): Promise<IFoundLyrics
const requestUrl = `https://genius.com${geniusPath}`;

try {
const response = await axios.get<string>(requestUrl);
const response = await axios.get<string>(requestUrl, {
validateStatus: status => status === 200 || status === 404
});

if (response.status === 404) {
return null;
}

const html = response.data;
const $ = cheerio.load(html); // Load in the page
Expand All @@ -171,8 +177,25 @@ export const getLyricsForPath = async (geniusPath: string): Promise<IFoundLyrics
syncedLyrics: null
} as IFoundLyrics;
} catch (e) {
console.error(`Failed to call '${requestUrl}'`);
console.error(e);
// Anything non-200 or 404 is considered an error
console.warn(`Failed to call '${requestUrl}'`);

if (e instanceof Error && e.stack !== undefined) {
console.warn(e.stack);
}

if (axios.isAxiosError(e)) {
if (e.response !== undefined) {
console.log(`Response: HTTP${e.response.status} ${e.response.statusText}`);
console.log(`Response headers: ${JSON.stringify(e.response.headers)}`);
console.log(`Response data: ${JSON.stringify(e.response.data)}`);
} else {
console.log("No response");
}
} else {
console.warn(e);
}

return null;
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/api/lrclib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function getLyrics(
attribution: LRCLIB_BASE_URL
} as IFoundLyrics;
} catch (e) {
// Can include 404 and anything else non-2xx
// Anything non-200 or 404 is considered an error
console.warn(`Failed to call '${requestUrl}'`);

if (e instanceof Error && e.stack !== undefined) {
Expand All @@ -81,6 +81,8 @@ export async function getLyrics(
console.log(`Response: HTTP${e.response.status} ${e.response.statusText}`);
console.log(`Response headers: ${JSON.stringify(e.response.headers)}`);
console.log(`Response data: ${JSON.stringify(e.response.data)}`);
} else {
console.log("No response");
}
} else {
console.warn(e);
Expand Down

0 comments on commit 0b0075e

Please sign in to comment.