mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor: catch withtyped errors
This commit is contained in:
parent
eee4317dac
commit
3c9b1eaafe
2 changed files with 17 additions and 10 deletions
|
@ -19,6 +19,7 @@ import RadioGroup, { Radio } from '@/ds-components/RadioGroup';
|
||||||
import TextInput from '@/ds-components/TextInput';
|
import TextInput from '@/ds-components/TextInput';
|
||||||
import useTheme from '@/hooks/use-theme';
|
import useTheme from '@/hooks/use-theme';
|
||||||
import modalStyles from '@/scss/modal.module.scss';
|
import modalStyles from '@/scss/modal.module.scss';
|
||||||
|
import { trySubmitSafe } from '@/utils/form';
|
||||||
|
|
||||||
import EnvTagOptionContent from './EnvTagOptionContent';
|
import EnvTagOptionContent from './EnvTagOptionContent';
|
||||||
import SelectTenantPlanModal from './SelectTenantPlanModal';
|
import SelectTenantPlanModal from './SelectTenantPlanModal';
|
||||||
|
@ -57,16 +58,18 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
|
||||||
};
|
};
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
|
|
||||||
const onCreateClick = handleSubmit(async (data: CreateTenantData) => {
|
const onCreateClick = handleSubmit(
|
||||||
const { tag } = data;
|
trySubmitSafe(async (data: CreateTenantData) => {
|
||||||
if (tag === TenantTag.Development) {
|
const { tag } = data;
|
||||||
await createTenant(data);
|
if (tag === TenantTag.Development) {
|
||||||
toast.success(t('tenants.create_modal.tenant_created'));
|
await createTenant(data);
|
||||||
return;
|
toast.success(t('tenants.create_modal.tenant_created'));
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setTenantData(data);
|
setTenantData(data);
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { ResponseError } from '@withtyped/client';
|
||||||
import { HTTPError, TimeoutError } from 'ky';
|
import { HTTPError, TimeoutError } from 'ky';
|
||||||
import { type FieldValues, type SubmitHandler } from 'react-hook-form';
|
import { type FieldValues, type SubmitHandler } from 'react-hook-form';
|
||||||
import { toast } from 'react-hot-toast';
|
import { toast } from 'react-hot-toast';
|
||||||
|
@ -16,7 +17,10 @@ export const trySubmitSafe =
|
||||||
try {
|
try {
|
||||||
await handler(formData, event);
|
await handler(formData, event);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof HTTPError && error.response.status !== 401) {
|
if (
|
||||||
|
(error instanceof HTTPError || error instanceof ResponseError) &&
|
||||||
|
error.response.status !== 401
|
||||||
|
) {
|
||||||
// Returned directly, since the error has been handled by the `use-api` hook.
|
// Returned directly, since the error has been handled by the `use-api` hook.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue