Handle network requests failing more gracefully
This commit is contained in:
parent
040b427d97
commit
9eb25f706e
51
src/index.ts
51
src/index.ts
@ -22,34 +22,39 @@ void (async () => {
|
||||
await getMangaToFetch(config);
|
||||
|
||||
for (const mangaId of uniqueMangaIds) {
|
||||
const lastChapterId = await mangaHistory.get<ChapterId>(mangaId);
|
||||
try {
|
||||
const lastChapterId = await mangaHistory.get<ChapterId>(mangaId);
|
||||
|
||||
const manga = await getManga(mangaId, userAgent);
|
||||
const chapters = await getAllChapters(mangaId, userAgent);
|
||||
const latestChapter = getLatestChapter(chapters);
|
||||
const cover = await getCover(manga, userAgent);
|
||||
const title = getMangaTitle(manga);
|
||||
const manga = await getManga(mangaId, userAgent);
|
||||
const chapters = await getAllChapters(mangaId, userAgent);
|
||||
const latestChapter = getLatestChapter(chapters);
|
||||
const cover = await getCover(manga, userAgent);
|
||||
const title = getMangaTitle(manga);
|
||||
|
||||
if (lastChapterId !== latestChapter.id) {
|
||||
console.log('Update found for manga:', title);
|
||||
if (lastChapterId !== latestChapter.id) {
|
||||
console.log('Update found for manga:', title);
|
||||
|
||||
const webhooksForManga = mangaIdsToWebhooks[mangaId];
|
||||
const webhooksForManga = mangaIdsToWebhooks[mangaId];
|
||||
|
||||
await Promise.all(
|
||||
webhooksForManga.map(
|
||||
async (webhookUrl) =>
|
||||
await sendWebhook({
|
||||
webhookUrl,
|
||||
manga,
|
||||
latestChapter,
|
||||
cover,
|
||||
}),
|
||||
),
|
||||
);
|
||||
await Promise.all(
|
||||
webhooksForManga.map(
|
||||
async (webhookUrl) =>
|
||||
await sendWebhook({
|
||||
webhookUrl,
|
||||
manga,
|
||||
latestChapter,
|
||||
cover,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
await mangaHistory.set(mangaId, latestChapter.id);
|
||||
} else {
|
||||
console.log('No Updates found for manga:', title);
|
||||
await mangaHistory.set(mangaId, latestChapter.id);
|
||||
} else {
|
||||
console.log('No Updates found for manga:', title);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Failed to fetch ${mangaId}!`);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user