Skip to content

Commit

Permalink
refactor(app): remove RequestError class
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhthomas committed Jan 11, 2025
1 parent 4db1d75 commit 033ccac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -94,23 +93,25 @@ const LinkJellyfinModal: React.FC<LinkJellyfinModalProps> = ({
}),
}
);
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));
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}
};

Expand Down Expand Up @@ -169,7 +168,7 @@ const UserLinkedAccountsSettings = () => {
</h3>
</div>
<Alert
title={intl.formatMessage(messages.nopermissionDescription)}
title={intl.formatMessage(messages.noPermissionDescription)}
type="error"
/>
</>
Expand Down
11 changes: 0 additions & 11 deletions src/types/error.ts

This file was deleted.

0 comments on commit 033ccac

Please sign in to comment.