diff --git a/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx b/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx index a9a99cc71..4872e7c15 100644 --- a/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx +++ b/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/LinkJellyfinModal.tsx @@ -2,7 +2,6 @@ import Alert from '@app/components/Common/Alert'; import Modal from '@app/components/Common/Modal'; import useSettings from '@app/hooks/useSettings'; import { useUser } from '@app/hooks/useUser'; -import { RequestError } from '@app/types/error'; import defineMessages from '@app/utils/defineMessages'; import { Transition } from '@headlessui/react'; import { MediaServerType } from '@server/constants/server'; @@ -94,23 +93,25 @@ const LinkJellyfinModal: React.FC = ({ }), } ); - if (!res.ok) throw new RequestError(res); - - onSave(); - } catch (e) { - if (e instanceof RequestError && e.status == 401) { - setError( - intl.formatMessage(messages.errorUnauthorized, { - mediaServerName, - }) - ); - } else if (e instanceof RequestError && e.status == 422) { - setError( - intl.formatMessage(messages.errorExists, { applicationName }) - ); + if (!res.ok) { + if (res.status === 401) { + setError( + intl.formatMessage(messages.errorUnauthorized, { + mediaServerName, + }) + ); + } else if (res.status === 422) { + setError( + intl.formatMessage(messages.errorExists, { applicationName }) + ); + } else { + setError(intl.formatMessage(messages.errorUnknown)); + } } else { - setError(intl.formatMessage(messages.errorUnknown)); + onSave(); } + } catch (e) { + setError(intl.formatMessage(messages.errorUnknown)); } }} > diff --git a/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/index.tsx b/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/index.tsx index ec13b2030..c83a15790 100644 --- a/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/index.tsx +++ b/src/components/UserProfile/UserSettings/UserLinkedAccountsSettings/index.tsx @@ -8,7 +8,6 @@ import PageTitle from '@app/components/Common/PageTitle'; import useSettings from '@app/hooks/useSettings'; import { Permission, UserType, useUser } from '@app/hooks/useUser'; import globalMessages from '@app/i18n/globalMessages'; -import { RequestError } from '@app/types/error'; import defineMessages from '@app/utils/defineMessages'; import PlexOAuth from '@app/utils/plex'; import { TrashIcon } from '@heroicons/react/24/solid'; @@ -100,18 +99,18 @@ const UserLinkedAccountsSettings = () => { } ); if (!res.ok) { - throw new RequestError(res); - } - - await revalidateUser(); - } catch (e) { - if (e instanceof RequestError && e.status === 401) { - setError(intl.formatMessage(messages.plexErrorUnauthorized)); - } else if (e instanceof RequestError && e.status === 422) { - setError(intl.formatMessage(messages.plexErrorExists)); + if (res.status === 401) { + setError(intl.formatMessage(messages.plexErrorUnauthorized)); + } else if (res.status === 422) { + setError(intl.formatMessage(messages.plexErrorExists)); + } else { + setError(intl.formatMessage(messages.errorUnknown)); + } } else { - setError(intl.formatMessage(messages.errorServer)); + await revalidateUser(); } + } catch (e) { + setError(intl.formatMessage(messages.errorUnknown)); } }; @@ -169,7 +168,7 @@ const UserLinkedAccountsSettings = () => { diff --git a/src/types/error.ts b/src/types/error.ts deleted file mode 100644 index 29507b388..000000000 --- a/src/types/error.ts +++ /dev/null @@ -1,11 +0,0 @@ -export class RequestError extends Error { - status: number; - res: Response; - - constructor(res: Response) { - const status = res.status; - super(`Request failed with status code ${status}`); - this.status = status; - this.res = res; - } -}