mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(console): input invalid format content in multitextinput will not crash the app
This commit is contained in:
parent
2e0ab8988a
commit
035be481cc
2 changed files with 10 additions and 2 deletions
|
@ -2,7 +2,7 @@ import { z } from 'zod';
|
|||
|
||||
export const multiTextInputErrorGuard = z.object({
|
||||
required: z.string().optional(),
|
||||
inputs: z.record(z.number(), z.string().optional()).optional(),
|
||||
inputs: z.record(z.number().or(z.string()), z.string().optional()).optional(),
|
||||
});
|
||||
|
||||
export type MultiTextInputError = z.infer<typeof multiTextInputErrorGuard>;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { t } from 'i18next';
|
||||
|
||||
import { safeParseJson } from '@/utilities/json';
|
||||
|
||||
import { MultiTextInputError, multiTextInputErrorGuard, MultiTextInputRule } from './types';
|
||||
|
||||
export const validate = (
|
||||
|
@ -57,7 +59,13 @@ export const convertRhfErrorMessage = (errorMessage?: string): MultiTextInputErr
|
|||
return;
|
||||
}
|
||||
|
||||
const result = multiTextInputErrorGuard.safeParse(errorMessage);
|
||||
const jsonParseResult = safeParseJson(errorMessage);
|
||||
|
||||
if (!jsonParseResult.success) {
|
||||
throw new Error(t('admin_console.errors.invalid_error_message_format'));
|
||||
}
|
||||
|
||||
const result = multiTextInputErrorGuard.safeParse(jsonParseResult.data);
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(t('admin_console.errors.invalid_error_message_format'));
|
||||
|
|
Loading…
Reference in a new issue