Skip to content

Commit 223ed3b

Browse files
authored
feat: add custom exceptions (#1573)
1 parent 66b0c68 commit 223ed3b

File tree

1 file changed

+66
-0
lines changed
  • packages/neuron-ui/src/exceptions

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ErrorCode } from 'utils/const'
2+
3+
export class FieldInvalidException extends Error {
4+
public code = ErrorCode.FieldInvalid
5+
public i18n: {
6+
fieldName: string
7+
}
8+
9+
constructor(fieldName: string) {
10+
super(`messages.codes.${ErrorCode.FieldInvalid}`)
11+
this.i18n = {
12+
fieldName,
13+
}
14+
}
15+
}
16+
17+
export class FieldRequiredException extends Error {
18+
public code = ErrorCode.FieldRequired
19+
public i18n: {
20+
fieldName: string
21+
}
22+
23+
constructor(fieldName: string) {
24+
super(`messages.codes.${ErrorCode.FieldRequired}`)
25+
this.i18n = { fieldName }
26+
}
27+
}
28+
29+
export class FieldTooLongException extends Error {
30+
public code = ErrorCode.FieldTooLong
31+
public i18n: {
32+
fieldName: string
33+
length: number
34+
}
35+
36+
constructor(fieldName: string, length: number) {
37+
super(`messages.codes.${ErrorCode.FieldTooLong}`)
38+
this.i18n = {
39+
fieldName,
40+
length,
41+
}
42+
}
43+
}
44+
45+
export class FieldUsedException extends Error {
46+
public code = ErrorCode.FieldUsed
47+
public i18n: {
48+
fieldName: string
49+
}
50+
51+
constructor(fieldName: string) {
52+
super(`messages.codes.${ErrorCode.FieldUsed}`)
53+
this.i18n = {
54+
fieldName,
55+
}
56+
}
57+
}
58+
59+
export class AmountNotEnoughException extends Error {
60+
public code = ErrorCode.AmountNotEnough
61+
constructor() {
62+
super(`messages.codes.${ErrorCode.AmountNotEnough}`)
63+
}
64+
}
65+
66+
export default undefined

0 commit comments

Comments
 (0)