mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-10 13:21:00 +00:00
fix(frontend): preserve cancellation and reject invalid query data (#6143)
* fix(frontend): preserve request cancellation and schema failures * fix(frontend): limit schema failures to query boundaries * fix(frontend): keep invalid settings recoverable Keep settings payload validation tolerant so values accepted by the backend remain editable, while paged clients still fail closed. Add an AbortSignal.any fallback and make timeout tests event-driven. --------- Co-authored-by: PathGao <gaoyanbo@gaoyanbodeMacBook-Air.local>
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import type { z } from 'zod';
|
||||
import { Msg } from '@/utils';
|
||||
|
||||
interface ParseMsgOptions {
|
||||
strict?: boolean;
|
||||
}
|
||||
|
||||
export function parseMsg<T extends z.ZodType>(
|
||||
msg: Msg<unknown>,
|
||||
schema: T,
|
||||
context: string,
|
||||
options: ParseMsgOptions = {},
|
||||
): Msg<z.infer<T>> {
|
||||
if (!msg.success || msg.obj == null) {
|
||||
return msg as Msg<z.infer<T>>;
|
||||
@@ -12,6 +17,7 @@ export function parseMsg<T extends z.ZodType>(
|
||||
const result = schema.safeParse(msg.obj);
|
||||
if (!result.success) {
|
||||
console.warn(`[zod] ${context} response failed validation`, result.error.issues);
|
||||
if (options.strict) throw new Error(`${context} response failed validation`);
|
||||
return msg as Msg<z.infer<T>>;
|
||||
}
|
||||
return new Msg<z.infer<T>>(msg.success, msg.msg, result.data);
|
||||
|
||||
Reference in New Issue
Block a user