feat(image): 新建 knowai-core:1.0.0 镜像并完成推送
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
This commit is contained in:
67
auth/errors.ts
Normal file
67
auth/errors.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 认证模块错误处理
|
||||
*/
|
||||
|
||||
/**
|
||||
* 认证错误类
|
||||
*/
|
||||
export class AuthError extends Error {
|
||||
public readonly code: string;
|
||||
public readonly details: unknown;
|
||||
|
||||
constructor(code: string, message: string, details?: unknown) {
|
||||
super(message);
|
||||
this.name = 'AuthError';
|
||||
this.code = code;
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建登录失败错误
|
||||
*/
|
||||
static loginFailed(message: string, details?: unknown): AuthError {
|
||||
return new AuthError('LOGIN_FAILED', message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建登出失败错误
|
||||
*/
|
||||
static logoutFailed(message: string, details?: unknown): AuthError {
|
||||
return new AuthError('LOGOUT_FAILED', message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建注册失败错误
|
||||
*/
|
||||
static registerFailed(message: string, details?: unknown): AuthError {
|
||||
return new AuthError('REGISTER_FAILED', message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建用户未找到错误
|
||||
*/
|
||||
static userNotFound(message: string, details?: unknown): AuthError {
|
||||
return new AuthError('USER_NOT_FOUND', message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* Session过期
|
||||
*/
|
||||
static sessionExpired(message: string, details?: unknown): AuthError {
|
||||
return new AuthError('SESSION_EXPIRED', message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* Session未认证
|
||||
*/
|
||||
static notAuthenticated(message: string = 'User not authenticated', details?: unknown): AuthError {
|
||||
return new AuthError('NOT_AUTHENTICATED', message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用未知报错
|
||||
*/
|
||||
static unknown(message: string = 'Unknown authentication error', details?: unknown): AuthError {
|
||||
return new AuthError('UNKNOWN', message, details);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user