Files
OCS_service/server/utils/response.ts
T
2026-05-23 13:45:58 +08:00

17 lines
524 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// server/utils/response.ts - 统一 API 响应工具函数(非 OCS 接口专用)
// OCS 搜题接口 /api/search 有固定的兼容格式,不使用此工具
/** 成功响应:code 0data 为业务数据,msg 固定为"请求成功" */
export const apiOk = <T>(data: T) => ({
code: 0 as const,
data,
msg: "请求成功"
});
/** 错误响应:data 固定为 null,msg 为本地安全文案,不暴露上游细节 */
export const apiErr = (code: number, msg: string) => ({
code,
data: null,
msg
});