diff options
| author | Fuwn <[email protected]> | 2026-01-23 21:26:36 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-23 21:26:36 -0800 |
| commit | e30cc3795166a372876969fd83b813472043b48b (patch) | |
| tree | fc672e36c5d64a804963029a9fe8cc413fc4c220 /src/lib/Data/AniList | |
| parent | fix(stores): Use unknown cast for dynamic property access (diff) | |
| download | due.moe-e30cc3795166a372876969fd83b813472043b48b.tar.xz due.moe-e30cc3795166a372876969fd83b813472043b48b.zip | |
fix: Add null guards and improve error messaging for user lookups
Diffstat (limited to 'src/lib/Data/AniList')
| -rw-r--r-- | src/lib/Data/AniList/following.ts | 6 | ||||
| -rw-r--r-- | src/lib/Data/AniList/forum.ts | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/lib/Data/AniList/following.ts b/src/lib/Data/AniList/following.ts index b4772afa..bec1f53c 100644 --- a/src/lib/Data/AniList/following.ts +++ b/src/lib/Data/AniList/following.ts @@ -33,7 +33,11 @@ const followingPage = async (page: number, id: number): Promise<FollowingPage> = export const followers = async (name: string): Promise<Partial<User>[]> => { const activities = []; let page = 1; - const id = (await user(name)).id; + const userData = await user(name); + + if (!userData) throw new Error(`User not found: ${name}`); + + const id = userData.id; let currentPage = await followingPage(page, id); for (const activity of currentPage.data.Page.following) activities.push(activity); diff --git a/src/lib/Data/AniList/forum.ts b/src/lib/Data/AniList/forum.ts index b2467c9e..c8514fe1 100644 --- a/src/lib/Data/AniList/forum.ts +++ b/src/lib/Data/AniList/forum.ts @@ -47,7 +47,11 @@ const threadPage = async (page: number, userId: number): Promise<ThreadPage> => export const threads = async (username: string): Promise<Thread[]> => { const allThreads = []; - const userId = (await user(username)).id; + const userData = await user(username); + + if (!userData) throw new Error(`User not found: ${username}`); + + const userId = userData.id; let page = 1; let currentPage = await threadPage(page, userId); |