App.svelte: - Import and render ErrorModal component - Add ErrorModal to main app layout below Header CheckIfAniListLoggedInAndLoadWatchList.svelte: - Import error state helpers (setApiError, clearApiError) - Wrap LoadAniListUser in try-catch with error handling - Wrap LoadAniListWatchList in try-catch with error handling - Update CheckIfAniListLoggedInAndLoadWatchList with error handling - Remove old alert() calls in favor of modal system Home.svelte: - Import isApiDown and apiError stores - Add conditional rendering for API down state - Display user-friendly "API Unavailable" message when apiError is set - Show warning icon and helpful messaging Error handling is now fully integrated across the frontend application.
82 lines
2.1 KiB
Svelte
82 lines
2.1 KiB
Svelte
<script lang="ts" context="module">
|
|
import {
|
|
CheckIfAniListLoggedIn,
|
|
GetAniListLoggedInUser,
|
|
GetAniListUserWatchingList,
|
|
} from "../../wailsjs/go/main/App";
|
|
import {
|
|
aniListUser,
|
|
watchListPage,
|
|
animePerPage,
|
|
aniListPrimary,
|
|
aniListLoggedIn,
|
|
aniListWatchlist,
|
|
aniListSort,
|
|
clearApiError,
|
|
setApiError,
|
|
} from "./GlobalVariablesAndHelperFunctions.svelte";
|
|
|
|
let isAniListPrimary: boolean;
|
|
let page: number;
|
|
let perPage: number;
|
|
let sort: string;
|
|
|
|
aniListPrimary.subscribe((value) => (isAniListPrimary = value));
|
|
watchListPage.subscribe((value) => (page = value));
|
|
animePerPage.subscribe((value) => (perPage = value));
|
|
aniListSort.subscribe((value) => (sort = value));
|
|
|
|
export const LoadAniListUser = async () => {
|
|
try {
|
|
await GetAniListLoggedInUser().then((user) => {
|
|
aniListUser.set(user);
|
|
});
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
setApiError(
|
|
"anilist",
|
|
`Failed to load user: ${errorMsg}`,
|
|
undefined,
|
|
true,
|
|
);
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
export const LoadAniListWatchList = async () => {
|
|
try {
|
|
const watchList = await GetAniListUserWatchingList(page, perPage, sort);
|
|
aniListWatchlist.set(watchList);
|
|
clearApiError();
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
setApiError(
|
|
"anilist",
|
|
`Failed to load watch list: ${errorMsg}`,
|
|
undefined,
|
|
true,
|
|
);
|
|
throw err;
|
|
}
|
|
};
|
|
export const CheckIfAniListLoggedInAndLoadWatchList = async () => {
|
|
try {
|
|
const loggedIn = await CheckIfAniListLoggedIn();
|
|
if (loggedIn) {
|
|
await LoadAniListUser();
|
|
if (isAniListPrimary) await LoadAniListWatchList();
|
|
}
|
|
aniListLoggedIn.set(loggedIn);
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
setApiError(
|
|
"anilist",
|
|
`Authentication failed: ${errorMsg}`,
|
|
undefined,
|
|
true,
|
|
);
|
|
aniListLoggedIn.set(false);
|
|
}
|
|
};
|
|
</script>
|