mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(console): improve error handling in connector details and sender tester
This commit is contained in:
parent
64bb5fd159
commit
d9ce4a0154
4 changed files with 24 additions and 14 deletions
|
@ -21,7 +21,6 @@ type Props = {
|
||||||
const ConnectorContent = ({ connectorData, onConnectorUpdated }: Props) => {
|
const ConnectorContent = ({ connectorData, onConnectorUpdated }: Props) => {
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
const [config, setConfig] = useState<string>();
|
const [config, setConfig] = useState<string>();
|
||||||
const [saveError, setSaveError] = useState<string>();
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
|
|
||||||
|
@ -54,10 +53,8 @@ const ConnectorContent = ({ connectorData, onConnectorUpdated }: Props) => {
|
||||||
}, [config, defaultConfig]);
|
}, [config, defaultConfig]);
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
setSaveError(undefined);
|
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
setSaveError(t('connector_details.save_error_empty_config'));
|
toast(t('connector_details.save_error_empty_config'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +75,9 @@ const ConnectorContent = ({ connectorData, onConnectorUpdated }: Props) => {
|
||||||
toast.success(t('general.saved'));
|
toast.success(t('general.saved'));
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof SyntaxError) {
|
if (error instanceof SyntaxError) {
|
||||||
setSaveError(t('connector_details.save_error_json_parse_error'));
|
toast.error(t('connector_details.save_error_json_parse_error'));
|
||||||
|
} else {
|
||||||
|
toast.error(t('errors.unexpected_error'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +104,6 @@ const ConnectorContent = ({ connectorData, onConnectorUpdated }: Props) => {
|
||||||
config={config}
|
config={config}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{saveError && <div>{saveError}</div>}
|
|
||||||
</div>
|
</div>
|
||||||
<div className={detailsStyles.footer}>
|
<div className={detailsStyles.footer}>
|
||||||
<div className={detailsStyles.footerMain}>
|
<div className={detailsStyles.footerMain}>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { phoneRegEx, emailRegEx } from '@logto/shared';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { toast } from 'react-hot-toast';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
|
@ -55,8 +56,9 @@ const SenderTester = ({ connectorId, connectorType, config, className }: Props)
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (formData) => {
|
const onSubmit = handleSubmit(async (formData) => {
|
||||||
const { sendTo } = formData;
|
const { sendTo } = formData;
|
||||||
const configJson = config ? (JSON.parse(config) as JSON) : undefined;
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
const configJson = config ? (JSON.parse(config) as JSON) : undefined;
|
||||||
const data = { config: configJson, ...(isSms ? { phone: sendTo } : { email: sendTo }) };
|
const data = { config: configJson, ...(isSms ? { phone: sendTo } : { email: sendTo }) };
|
||||||
|
|
||||||
await api
|
await api
|
||||||
|
@ -64,7 +66,15 @@ const SenderTester = ({ connectorId, connectorType, config, className }: Props)
|
||||||
json: data,
|
json: data,
|
||||||
})
|
})
|
||||||
.json();
|
.json();
|
||||||
|
|
||||||
setShowTooltip(true);
|
setShowTooltip(true);
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof SyntaxError) {
|
||||||
|
toast.error(t('connector_details.save_error_json_parse_error'));
|
||||||
|
} else {
|
||||||
|
toast.error(t('errors.unexpected_error'));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -59,6 +59,7 @@ const translation = {
|
||||||
username_pattern_error:
|
username_pattern_error:
|
||||||
'Username should only contain letters, numbers, or underscore and should not start with a number.',
|
'Username should only contain letters, numbers, or underscore and should not start with a number.',
|
||||||
password_pattern_error: 'Password requires a minimum of 6 characters',
|
password_pattern_error: 'Password requires a minimum of 6 characters',
|
||||||
|
unexpected_error: 'An unexpected error occurred',
|
||||||
},
|
},
|
||||||
tab_sections: {
|
tab_sections: {
|
||||||
overview: 'Overview',
|
overview: 'Overview',
|
||||||
|
|
|
@ -59,6 +59,7 @@ const translation = {
|
||||||
more_details: '查看详情',
|
more_details: '查看详情',
|
||||||
username_pattern_error: '用户名只能包含英文字母、数字或下划线,且不以数字开头。',
|
username_pattern_error: '用户名只能包含英文字母、数字或下划线,且不以数字开头。',
|
||||||
password_pattern_error: '密码应不少于 6 位',
|
password_pattern_error: '密码应不少于 6 位',
|
||||||
|
unexpected_error: '发生未知错误',
|
||||||
},
|
},
|
||||||
tab_sections: {
|
tab_sections: {
|
||||||
overview: '概览',
|
overview: '概览',
|
||||||
|
|
Loading…
Reference in a new issue