From c1f7bd4bfb0ecc9f7efb2764c4f3bba9b6452928 Mon Sep 17 00:00:00 2001 From: Owais Jamil Date: Tue, 9 Jun 2026 12:38:15 -0500 Subject: [PATCH] refactor: create shared error utility --- src/lib/atproto/repo.svelte.ts | 9 +++------ src/lib/components/SetupDialog.svelte | 3 ++- src/lib/db/client.ts | 7 ++----- src/lib/utils/errors.ts | 13 +++++++++++++ src/routes/+layout.svelte | 5 +++-- 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 src/lib/utils/errors.ts diff --git a/src/lib/atproto/repo.svelte.ts b/src/lib/atproto/repo.svelte.ts index cdc5048..39a948c 100644 --- a/src/lib/atproto/repo.svelte.ts +++ b/src/lib/atproto/repo.svelte.ts @@ -1,6 +1,7 @@ import { Client, ok, simpleFetchHandler } from '@atcute/client'; import type { ActorIdentifier, Nsid } from '@atcute/lexicons/syntax'; import type {} from '@atcute/atproto'; +import { errorMessage } from '$lib/utils/errors'; import type { AccountIdentity } from './identity'; export type CollectionSummary = { name: string; icon: string; loadedCount: number | null }; @@ -56,7 +57,7 @@ class RepoBrowserState { await this.selectCollection(identity, this.selectedCollection); } } catch (unknownError) { - this.error = messageFromError(unknownError, 'Could not load repository collections.'); + this.error = errorMessage(unknownError, 'Could not load repository collections.'); } finally { this.isLoadingCollections = false; } @@ -86,7 +87,7 @@ class RepoBrowserState { ); } catch (unknownError) { this.records = []; - this.error = messageFromError(unknownError, `Could not load records for ${collectionName}.`); + this.error = errorMessage(unknownError, `Could not load records for ${collectionName}.`); } finally { this.isLoadingRecords = false; } @@ -178,7 +179,3 @@ function formatRecordTime(value: string | null) { minute: '2-digit' }).format(date); } - -function messageFromError(error: unknown, fallback: string) { - return error instanceof Error ? error.message : fallback; -} diff --git a/src/lib/components/SetupDialog.svelte b/src/lib/components/SetupDialog.svelte index c2bf5a9..58d06f1 100644 --- a/src/lib/components/SetupDialog.svelte +++ b/src/lib/components/SetupDialog.svelte @@ -1,6 +1,7 @@