Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use gerror #50

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"dependencies": {
"flash-store": "^0.12.7",
"fs-extra": "^8.1.0",
"gerror": "^1.0.16",
"rxjs": "^7.5.1",
"wechaty-puppet": "^0.41.9",
"whatsapp-web.js": "^1.15.3"
Expand Down
18 changes: 14 additions & 4 deletions src/pure-function-helpers/error-type.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import type { WAErrorType } from '../schema/error-type'
import { WAErrorType, WXWORK_ERROR_TYPE } from '../schema/error-type.js'
import { GError } from 'gerror'

export default class WAError extends Error {
export default class WAError {

constructor (type: WAErrorType, message: string) {
super(`${type} ${message}`)
constructor (
type: WAErrorType,
message: string,
details?: string,
) {
GError.from({
code: type,
details,
message,
name: WXWORK_ERROR_TYPE[type],
})
}

}
40 changes: 20 additions & 20 deletions src/schema/error-type.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
enum BASE_ERROR_TYPE {
ERR_REQUEST_TIMEOUT = 'ERR_REQUEST_TIMEOUT', // 请求超时
ERR_START = 'ERR_START', // 启动异常
ERR_STOP = 'ERR_STOP', // 停止异常
ERR_REQUEST_TIMEOUT = 1101, // 请求超时
ERR_START = 1102, // 启动异常
ERR_STOP = 1103, // 停止异常
}

enum INIT_ERROR_TYPE {
ERR_INIT = 'ERR_INIT', // 未初始化
ERR_NOT_LOGIN = 'ERR_NOT_LOGIN', // 未登录
ERR_CACHE_EXISTED = 'ERR_CACHE_EXISTED', // 缓存已存在
ERR_NO_CACHE = 'ERR_NO_CACHE', // 缓存无效
ERR_INIT = 1001, // 未初始化
ERR_NOT_LOGIN = 1002, // 未登录
ERR_CACHE_EXISTED = 1003, // 缓存已存在
ERR_NO_CACHE = 1004, // 缓存无效
}

enum MESSAGE_ERROR_TYPE {
ERR_SEND_MSG = 'ERR_SEND_MSG', // 发送消息失败
ERR_SEND_MSG_TIMEOUT = 'ERR_SEND_MSG_TIMEOUT', // 发送消息超时
ERR_UNKNOWN_SEND_STATUS = 'ERR_UNKNOWN_SEND_STATUS', // 未知消息发送结果
ERR_SEND_MSG = 2001, // 发送消息失败
ERR_SEND_MSG_TIMEOUT = 2002, // 发送消息超时
ERR_UNKNOWN_SEND_STATUS = 2003, // 未知消息发送结果
}

enum ROOM_ERROR_TYPE {
ERR_ROOM_NOT_FOUND = 'ERR_ROOM_NOT_FOUND', // 群聊不存在
ERR_CREATE_ROOM = 'ERR_CREATE_ROOM', // 创建群聊失败
ERR_MODIFY_ROOM_NAME = 'ERR_MODIFY_ROOM_NAME', // 修改群名称失败
ERR_ADD_ROOM = 'ERR_ADD_ROOM', // 拉人进群失败
ERR_REMOVE_ROOM = 'ERR_REMOVE_ROOM', // 踢人出群失败
ERR_ACCEPT_ROOM_INVITATION = 'ERR_ACCEPT_ROOM_INVITATION', // 自动通过群邀请失败
ERR_ANNOUNCE_NO_PERMISSION = 'ERR_ANNOUNCE_NO_PERMISSION', // 无发送群公告权限
ERR_ROOM_NOT_FOUND = 3001, // 群聊不存在
ERR_CREATE_ROOM = 3002, // 创建群聊失败
ERR_MODIFY_ROOM_NAME = 3003, // 修改群名称失败
ERR_ADD_ROOM = 3004, // 拉人进群失败
ERR_REMOVE_ROOM = 3005, // 踢人出群失败
ERR_ACCEPT_ROOM_INVITATION = 3006, // 自动通过群邀请失败
ERR_ANNOUNCE_NO_PERMISSION = 3007, // 无发送群公告权限
}

enum CONTACT_ERROR_TYPE {
ERR_CONTACT_NOT_FOUND = 'ERR_CONTACT_NOT_FOUND', // 联系人不存在
ERR_INVALID_CONTACT_ID = 'ERR_INVALID_CONTACT_ID', // 联系人ID无效
ERR_CONTACT_CARD_ID = 'ERR_CONTACT_CARD_ID', // 名片id异常
ERR_CONTACT_NOT_FOUND = 4001, // 联系人不存在
ERR_INVALID_CONTACT_ID = 4002, // 联系人ID无效
ERR_CONTACT_CARD_ID = 4003, // 名片id异常
}

export const WXWORK_ERROR_TYPE = {
Expand Down