fix: surface streamed load failures inline
The streamed loaders on bookmarks, collections, library, search, and the
collection detail page swallowed only ApiError into their in-band `error`
field and re-threw anything else. A raw network failure (a non-ApiError
TypeError from fetch) therefore escaped the `{#await}` to SvelteKit's
generic error page. On the collection detail page a content-load failure
showed a misleading "this collection is empty", and on search a failed
results query showed a false "no matches" because the streamed `error`
was never rendered.
Fold non-ApiError failures into the same in-band `error` so every
transient blip renders as an inline message, add a `contentError` branch
to the collection detail grid, and render the search results `error` in
both result views.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,10 +16,11 @@ export const load: PageLoad = async () => {
|
||||
if (e instanceof ApiError && e.status === 401) {
|
||||
return { collections: [], authenticated: false, error: null as string | null };
|
||||
}
|
||||
if (e instanceof ApiError) {
|
||||
return { collections: [], authenticated: true, error: e.message };
|
||||
}
|
||||
throw e;
|
||||
// An HTTP error or a raw network failure (a non-ApiError
|
||||
// TypeError) renders inline rather than escaping to the
|
||||
// framework error page for a transient API blip.
|
||||
const message = e instanceof ApiError ? e.message : 'Something went wrong.';
|
||||
return { collections: [], authenticated: true, error: message };
|
||||
}
|
||||
})()
|
||||
};
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
let mangas = $state<Manga[]>([]);
|
||||
let pages = $state<CollectionPageItem[]>([]);
|
||||
let contentLoading = $state(true);
|
||||
// Set when the streamed content fails to load, so we surface an inline
|
||||
// error instead of a misleading "this collection is empty".
|
||||
let contentError = $state<string | null>(null);
|
||||
|
||||
// Seed (and re-seed on navigation) from the streamed content. A monotonic
|
||||
// guard drops a stale resolution that lands after a newer navigation.
|
||||
@@ -37,6 +40,7 @@
|
||||
const content = data.content;
|
||||
const seq = ++contentSeq;
|
||||
contentLoading = true;
|
||||
contentError = null;
|
||||
content
|
||||
.then((r) => {
|
||||
if (seq !== contentSeq) return;
|
||||
@@ -44,8 +48,11 @@
|
||||
pages = r.pages;
|
||||
contentLoading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((e) => {
|
||||
if (seq !== contentSeq) return;
|
||||
mangas = [];
|
||||
pages = [];
|
||||
contentError = e instanceof Error ? e.message : 'Something went wrong.';
|
||||
contentLoading = false;
|
||||
});
|
||||
});
|
||||
@@ -203,6 +210,10 @@
|
||||
|
||||
{#if contentLoading}
|
||||
<MangaGridSkeleton count={6} />
|
||||
{:else if contentError}
|
||||
<p class="error" role="alert" data-testid="collection-content-error">
|
||||
Couldn't load this collection's contents: {contentError}
|
||||
</p>
|
||||
{:else if mangas.length === 0 && pages.length === 0}
|
||||
<p class="status" data-testid="collection-empty">
|
||||
This collection is empty.
|
||||
|
||||
Reference in New Issue
Block a user