fix: show cron validation field errors

This commit is contained in:
whyour
2026-08-22 01:20:04 +08:00
parent 134cd8337c
commit 0e975d1d6d
6 changed files with 112 additions and 7 deletions
+30
View File
@@ -0,0 +1,30 @@
export interface ValidationErrorResponse {
errors?: Array<{ message?: string; value?: unknown }>;
validation?: Record<
string,
{ source?: string; keys?: string[]; message?: string }
>;
}
export const getErrorDetails = (data?: ValidationErrorResponse) => {
const details =
data?.errors?.map((item) =>
item.value === undefined
? item.message
: `${item.message} (${String(item.value)})`,
) || [];
Object.values(data?.validation || {}).forEach((validation) => {
if (validation.keys?.length) {
validation.keys.forEach((key) => {
details.push(
validation.message ? `${key}: ${validation.message}` : key,
);
});
} else if (validation.message) {
details.push(validation.message);
}
});
return details.filter((detail): detail is string => Boolean(detail));
};