mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-17 07:20:51 +08:00
fix: show cron validation field errors
This commit is contained in:
@@ -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));
|
||||
};
|
||||
Reference in New Issue
Block a user