fix(plexpin): remove duplicate error handling and reset pin on submit
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import Button from '@app/components/Common/Button';
|
import Button from '@app/components/Common/Button';
|
||||||
import defineMessages from '@app/utils/defineMessages';
|
import defineMessages from '@app/utils/defineMessages';
|
||||||
import { ApiErrorCode } from '@server/constants/error';
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
|
|
||||||
@@ -33,34 +32,12 @@ const PlexPinEntry = ({
|
|||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!pin || isSubmitting) return;
|
if (!pin || isSubmitting) return;
|
||||||
|
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await onSubmit(pin);
|
await onSubmit(pin);
|
||||||
|
setPin('');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const code = err?.response?.data?.error as string | undefined;
|
setPin('');
|
||||||
const httpStatus = err?.response?.status;
|
|
||||||
|
|
||||||
let msg: string;
|
|
||||||
switch (code) {
|
|
||||||
case ApiErrorCode.InvalidPin:
|
|
||||||
msg = intl.formatMessage(messages.invalidPin);
|
|
||||||
break;
|
|
||||||
case ApiErrorCode.NewPlexLoginDisabled:
|
|
||||||
msg = intl.formatMessage(messages.accessDenied);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (httpStatus === 401) {
|
|
||||||
msg = intl.formatMessage(messages.invalidPin);
|
|
||||||
} else if (httpStatus === 403) {
|
|
||||||
msg = intl.formatMessage(messages.accessDenied);
|
|
||||||
} else {
|
|
||||||
msg =
|
|
||||||
err?.response?.data?.message ??
|
|
||||||
intl.formatMessage(messages.invalidPin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user