diff --git a/frontend/src/functions/APIClient.ts b/frontend/src/functions/APIClient.ts index 21a5e734..48b7900a 100644 --- a/frontend/src/functions/APIClient.ts +++ b/frontend/src/functions/APIClient.ts @@ -10,6 +10,11 @@ export interface ApiClientOptions extends Omit { body?: Record | string; } +export interface ApiError { + status: number; + message: string; +} + const APIClient = async ( endpoint: string, { method = 'GET', body, headers = {}, ...options }: ApiClientOptions = {}, @@ -30,6 +35,14 @@ const APIClient = async ( }); // Handle common errors + if (response.status === 400) { + const data = await response.json(); + throw { + status: response.status, + message: data?.message || 'An error occurred while processing the request.', + } as ApiError; + } + if (response.status === 401) { logOut(); window.location.href = Routes.Login; diff --git a/frontend/src/pages/SettingsScheduling.tsx b/frontend/src/pages/SettingsScheduling.tsx index d3f50d93..d1ebd685 100644 --- a/frontend/src/pages/SettingsScheduling.tsx +++ b/frontend/src/pages/SettingsScheduling.tsx @@ -13,6 +13,7 @@ import createAppriseNotificationUrl, { AppriseTaskNameType, } from '../api/actions/createAppriseNotificationUrl'; import deleteAppriseNotificationUrl from '../api/actions/deleteAppriseNotificationUrl'; +import { ApiError } from '../functions/APIClient'; const SettingsScheduling = () => { const [refresh, setRefresh] = useState(false); @@ -29,6 +30,11 @@ const SettingsScheduling = () => { const [zipBackupDays, setZipBackupDays] = useState(); const [notificationUrl, setNotificationUrl] = useState(); const [notificationTask, setNotificationTask] = useState(''); + const [checkReindexError, setCheckReindexError] = useState(null); + const [updateSubscribedError, setUpdateSubscribedError] = useState(null); + const [downloadPendingError, setDownloadPendingError] = useState(null); + const [thumnailCheckError, setThumnailCheckError] = useState(null); + const [zipBackupError, setZipBackupError] = useState(null); useEffect(() => { (async () => { @@ -144,15 +150,24 @@ const SettingsScheduling = () => {