Files
CloudSearch/source_clean/src/cloud/error-codes.ts
admin 83cbfaf03f v0.2.7: 修复Redis连接 + 启动管理后台
- 修复Redis认证 (配置密码)
- 启动Python管理后台 (端口9531, 15个功能开关)
- 统一版本号 0.2.7
- 更新docker-compose.yml (镜像版本/Redis URL/Admin服务)
2026-05-17 02:22:18 +08:00

71 lines
3.1 KiB
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.
// Standard error codes for all cloud drivers
export const ErrCode = {
COOKIE_EXPIRED: 'COOKIE_EXPIRED',
COOKIE_INVALID: 'COOKIE_INVALID',
TOKEN_EXPIRED: 'TOKEN_EXPIRED',
SHARE_NOT_FOUND: 'SHARE_NOT_FOUND',
SHARE_EXPIRED: 'SHARE_EXPIRED',
PASSWORD_REQUIRED: 'PASSWORD_REQUIRED',
PASSWORD_WRONG: 'PASSWORD_WRONG',
CAPACITY_FULL: 'CAPACITY_FULL',
FILE_EXISTS: 'FILE_EXISTS',
RATE_LIMITED: 'RATE_LIMITED',
TRANSFER_FAILED: 'TRANSFER_FAILED',
NETWORK_ERROR: 'NETWORK_ERROR',
UNSUPPORTED: 'UNSUPPORTED',
UNKNOWN: 'UNKNOWN',
} as const;
export type ErrorCode = typeof ErrCode[keyof typeof ErrCode];
const messages: Record<string, string> = {
[ErrCode.COOKIE_EXPIRED]: 'Cookie已过期请重新登录',
[ErrCode.COOKIE_INVALID]: 'Cookie无效请检查配置',
[ErrCode.TOKEN_EXPIRED]: 'Token已过期请刷新',
[ErrCode.SHARE_NOT_FOUND]: '分享链接不存在或已被删除',
[ErrCode.SHARE_EXPIRED]: '分享链接已过期',
[ErrCode.PASSWORD_REQUIRED]: '需要提取码',
[ErrCode.PASSWORD_WRONG]: '提取码错误',
[ErrCode.CAPACITY_FULL]: '网盘容量不足',
[ErrCode.RATE_LIMITED]: '请求过于频繁,请稍后重试',
[ErrCode.TRANSFER_FAILED]: '转存失败',
[ErrCode.NETWORK_ERROR]: '网络请求失败',
[ErrCode.UNKNOWN]: '未知错误',
};
export function errorResponse(code: ErrorCode, detail?: string) {
return {
success: false,
code,
message: messages[code] + (detail ? ': ' + detail : ''),
};
}
export class TransferError extends Error {
code: ErrorCode;
detail?: string;
cookieExpired: boolean;
constructor(code: ErrorCode, detail?: string) {
super(messages[code] + (detail ? ': ' + detail : ''));
this.code = code;
this.detail = detail;
this.cookieExpired = (code === ErrCode.COOKIE_EXPIRED || code === ErrCode.COOKIE_INVALID);
}
}
/** Detect error code from driver result message (for untagged drivers) */
export function detectErrorCode(result: { message?: string; cookieExpired?: boolean }): ErrorCode | null {
if (!result || !result.message) return null;
if (result.cookieExpired) return ErrCode.COOKIE_EXPIRED;
const msg = result.message.toLowerCase();
if (msg.includes('cookie') || msg.includes('登录') || msg.includes('bdstoken')) return ErrCode.COOKIE_EXPIRED;
if (msg.includes('不存在') || msg.includes('not found') || msg.includes('已删除')) return ErrCode.SHARE_NOT_FOUND;
if (msg.includes('过期') || msg.includes('expired')) return ErrCode.SHARE_EXPIRED;
if (msg.includes('提取码') || msg.includes('密码') || msg.includes('password')) return ErrCode.PASSWORD_WRONG;
if (msg.includes('容量') || msg.includes('空间') || msg.includes('capacity')) return ErrCode.CAPACITY_FULL;
if (msg.includes('频繁') || msg.includes('稍后') || msg.includes('rate')) return ErrCode.RATE_LIMITED;
if (msg.includes('网络') || msg.includes('fetch') || msg.includes('timeout')) return ErrCode.NETWORK_ERROR;
return ErrCode.TRANSFER_FAILED;
}