Skip to content

Commit 6b9dad8

Browse files
committed
恢复die相关方法
1 parent 09e7e5f commit 6b9dad8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/die.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export class CoaContextError extends Error {
2+
3+
code: number
4+
mark: number | string
5+
custom: string
6+
stdout: boolean
7+
8+
constructor (e: { message: string, code: number, mark: number | string, custom?: string, stdout?: boolean }) {
9+
super()
10+
this.name = 'CoaContextError'
11+
this.message = e.message
12+
this.code = e.code
13+
this.mark = e.mark
14+
this.custom = e.custom || ''
15+
this.stdout = e.stdout || false
16+
}
17+
}
18+
19+
export const die = new class {
20+
21+
hint (message: string, code: number = 400, mark: number | string = 0): never {
22+
throw new CoaContextError({ code, mark, message })
23+
}
24+
25+
error (message: string, code: number = 400, mark: number | string = 0): never {
26+
throw new CoaContextError({ code, mark, message, stdout: true })
27+
}
28+
29+
custom (custom: string, message: string, code: number = 400, mark: number | string = 0): never {
30+
throw new CoaContextError({ code, mark, message, custom })
31+
}
32+
33+
missing (name: string) {
34+
return this.error('缺少' + name + '参数')
35+
}
36+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export { CoaError } from './CoaError'
2+
export { CoaContextError, die } from './die'
3+

0 commit comments

Comments
 (0)