mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-30 21:49:11 -05:00
refactor(app): remove RequestError class
This commit is contained in:
@@ -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<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));
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -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 = () => {
|
||||
</h3>
|
||||
</div>
|
||||
<Alert
|
||||
title={intl.formatMessage(messages.nopermissionDescription)}
|
||||
title={intl.formatMessage(messages.noPermissionDescription)}
|
||||
type="error"
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user