完成文档列表页面ui,封装部分上传文件的公共组件,封装请求接口

This commit is contained in:
2025-04-01 22:14:43 +08:00
parent 8fe88c1d15
commit 706cea8705
37 changed files with 4512 additions and 1459 deletions
+46
View File
@@ -0,0 +1,46 @@
/**
* API 错误类,用于封装 API 请求错误
*/
export class ApiError extends Error {
status: number;
constructor(message: string, status: number = 500) {
super(message);
this.name = 'ApiError';
this.status = status;
}
}
/**
* 处理 API 错误
* @param error 捕获的错误对象
* @returns 统一的 ApiError 对象
*/
export function handleApiError(error: unknown): ApiError {
if (error instanceof ApiError) {
return error;
}
if (error instanceof Error) {
return new ApiError(error.message);
}
return new ApiError('未知错误');
}
/**
* 创建一个标准的错误响应
* @param message 错误消息
* @param status HTTP 状态码
*/
export function createErrorResponse(message: string, status: number = 400): Response {
return new Response(
JSON.stringify({ error: message }),
{
status,
headers: {
'Content-Type': 'application/json'
}
}
);
}