feat: add error handling to search functions
This commit is contained in:
@@ -118,12 +118,13 @@ export const fetchSearchItems = (query: string): void => {
|
|||||||
responseCache.set(query, response);
|
responseCache.set(query, response);
|
||||||
renderItems(visibleItems);
|
renderItems(visibleItems);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
if (controller.signal.aborted) {
|
if (controller.signal.aborted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setActiveRequestController(undefined);
|
setActiveRequestController(undefined);
|
||||||
|
console.error("search request failed:", error);
|
||||||
renderSearchErrorState(query);
|
renderSearchErrorState(query);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -168,8 +169,9 @@ export const fetchNextSearchPage = (): void => {
|
|||||||
setSearchPagination(response.nextPage, response.hasNextPage);
|
setSearchPagination(response.nextPage, response.hasNextPage);
|
||||||
appendItems(visibleItems);
|
appendItems(visibleItems);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
window.showToast?.({ message: "Failed to load more search results." });
|
window.showToast?.({ message: "Failed to load more search results." });
|
||||||
|
console.error("failed to load more search results:", error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setFetchingNextPage(false);
|
setFetchingNextPage(false);
|
||||||
|
|||||||
@@ -140,8 +140,9 @@ export const removeContinueWatchingItem = (item: CommandPaletteItem): void => {
|
|||||||
removeContinueWatchingCard(animeID);
|
removeContinueWatchingCard(animeID);
|
||||||
renderItems(getResultItems().filter((candidate) => candidate.id !== item.id));
|
renderItems(getResultItems().filter((candidate) => candidate.id !== item.id));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
window.showToast?.({ message: "Failed to remove from Continue Watching." });
|
window.showToast?.({ message: "Failed to remove from Continue Watching." });
|
||||||
|
console.error("failed to remove from continue watching:", error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -177,7 +177,8 @@ export const isSafeImageUrl = (rawUrl?: string): boolean => {
|
|||||||
try {
|
try {
|
||||||
const parsed = new URL(rawUrl, window.location.origin);
|
const parsed = new URL(rawUrl, window.location.origin);
|
||||||
return parsed.protocol === "https:" || parsed.protocol === "http:";
|
return parsed.protocol === "https:" || parsed.protocol === "http:";
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error("Failed to validate URL:", error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user