diff --git a/components/settings/SettingToggles.tsx b/components/settings/SettingToggles.tsx index 8302c45b..2f55edaf 100644 --- a/components/settings/SettingToggles.tsx +++ b/components/settings/SettingToggles.tsx @@ -160,6 +160,9 @@ export const SettingToggles: React.FC = ({ ...props }) => { setJellyseerrUser(user); updateSettings({jellyseerrServerUrl}) }) + .catch(() => { + toast.error("Failed to login to jellyseerr!") + }) .finally(() => { setJellyseerrPassword(undefined); }) @@ -725,6 +728,8 @@ export const SettingToggles: React.FC = ({ ...props }) => { Set the URL for your jellyseerr instance. + Example: http(s)://your-host.url + (add port if required) This integration is in its early stages. Expect things to change. { - const user = response.data; + const user = response?.data; + if (!user) + throw Error("Login failed") storage.setAny(JELLYSEERR_USER, user); return user }) @@ -186,6 +195,27 @@ export class JellyseerrApi { } private setInterceptors() { + this.axios.interceptors.response.use( + async (response) => { + const cookies = response.headers["set-cookie"]; + if (cookies) { + storage.setAny(JELLYSEERR_COOKIES, response.headers["set-cookie"]?.flatMap(c => c.split("; "))); + } + return response; + }, + (error: AxiosError) => { + const errorMsg = "Jellyseerr response error:"; + console.error(errorMsg, error, error.response?.data); + writeErrorLog( + errorMsg + ` ${error.toString()}\n` + + JSON.stringify(error.response?.data) + ); + if (error.status === 403) { + clearJellyseerrStorageData() + } + } + ); + this.axios.interceptors.request.use( async (config) => { const cookies = storage.get(JELLYSEERR_COOKIES); @@ -204,22 +234,6 @@ export class JellyseerrApi { console.error("Jellyseerr request error", error) } ); - - this.axios.interceptors.response.use( - async (response) => { - const cookies = response.headers["set-cookie"]; - if (cookies) { - storage.setAny(JELLYSEERR_COOKIES, response.headers["set-cookie"]?.flatMap(c => c.split("; "))); - } - return response; - }, - (error: AxiosError) => { - console.error("Jellyseerr response error:", error,error.response?.data) - if (error.status === 403) { - clearJellyseerrStorageData() - } - } - ); } }