mirror of
https://github.com/logto-io/logto.git
synced 2025-01-13 21:30:30 -05:00
refactor(console): improve webhook test request error handling (#6017)
This commit is contained in:
parent
15a51a4426
commit
dc6fbe212e
1 changed files with 27 additions and 29 deletions
|
@ -4,7 +4,6 @@ import dayjs from 'dayjs';
|
|||
import { HTTPError } from 'ky';
|
||||
import { useRef, useState } from 'react';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Button from '@/ds-components/Button';
|
||||
|
@ -33,7 +32,9 @@ function TestWebhook({ hookId }: Props) {
|
|||
const { result, setResult } = useWebhookTestResult();
|
||||
|
||||
const [isSendingPayload, setIsSendingPayload] = useState(false);
|
||||
const api = useApi({ hideErrorToast: true });
|
||||
const api = useApi({
|
||||
hideErrorToast: ['hook.send_test_payload_failed', 'hook.endpoint_responded_with_error'],
|
||||
});
|
||||
|
||||
const sendTestPayload = async () => {
|
||||
if (isSendingPayload) {
|
||||
|
@ -57,11 +58,7 @@ function TestWebhook({ hookId }: Props) {
|
|||
requestTime,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
if (!(error instanceof HTTPError)) {
|
||||
toast.error(error instanceof Error ? String(error) : t('general.unknown_error'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (error instanceof HTTPError) {
|
||||
const { code, data, message } = await error.response.clone().json<RequestErrorBody>();
|
||||
|
||||
if (code === 'hook.send_test_payload_failed') {
|
||||
|
@ -89,6 +86,7 @@ function TestWebhook({ hookId }: Props) {
|
|||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
} finally {
|
||||
|
|
Loading…
Add table
Reference in a new issue