diff options
| author | Fuwn <[email protected]> | 2024-11-10 20:16:13 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-11-10 20:16:13 -0800 |
| commit | e54fefb0df5021ebf0e46b6bb07d45b90b14fd6c (patch) | |
| tree | ec8adfc53e98b579d274134db048e11441b9737b /src/lib/Data | |
| parent | deps: refresh bun lockfile (diff) | |
| download | due.moe-e54fefb0df5021ebf0e46b6bb07d45b90b14fd6c.tar.xz due.moe-e54fefb0df5021ebf0e46b6bb07d45b90b14fd6c.zip | |
feat(user): add simple null check for remote user identity fetch
Diffstat (limited to 'src/lib/Data')
| -rw-r--r-- | src/lib/Data/AniList/user.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lib/Data/AniList/user.ts b/src/lib/Data/AniList/user.ts index 5b9390db..aaab6e0b 100644 --- a/src/lib/Data/AniList/user.ts +++ b/src/lib/Data/AniList/user.ts @@ -45,8 +45,8 @@ export interface FullUser { about: string; } -export const user = async (username: string, id = false): Promise<User> => - ( +export const user = async (username: string, id = false): Promise<User | null> => { + const response = ( await ( await fetch('https://graphql.anilist.co', { method: 'POST', @@ -64,11 +64,14 @@ export const user = async (username: string, id = false): Promise<User> => count meanScore chaptersRead volumesRead } } - } }` + } }` }) }) ).json() - )['data']['User']; + ) + + return response["data"]["User"] === null ? null : response["data"]["User"]; +} export const dumpUser = async (username: string): Promise<FullUser> => ( |