Skip to content

Commit

Permalink
feat: add custom exceptions (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Apr 28, 2020
1 parent 66b0c68 commit 223ed3b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/neuron-ui/src/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ErrorCode } from 'utils/const'

export class FieldInvalidException extends Error {
public code = ErrorCode.FieldInvalid
public i18n: {
fieldName: string
}

constructor(fieldName: string) {
super(`messages.codes.${ErrorCode.FieldInvalid}`)
this.i18n = {
fieldName,
}
}
}

export class FieldRequiredException extends Error {
public code = ErrorCode.FieldRequired
public i18n: {
fieldName: string
}

constructor(fieldName: string) {
super(`messages.codes.${ErrorCode.FieldRequired}`)
this.i18n = { fieldName }
}
}

export class FieldTooLongException extends Error {
public code = ErrorCode.FieldTooLong
public i18n: {
fieldName: string
length: number
}

constructor(fieldName: string, length: number) {
super(`messages.codes.${ErrorCode.FieldTooLong}`)
this.i18n = {
fieldName,
length,
}
}
}

export class FieldUsedException extends Error {
public code = ErrorCode.FieldUsed
public i18n: {
fieldName: string
}

constructor(fieldName: string) {
super(`messages.codes.${ErrorCode.FieldUsed}`)
this.i18n = {
fieldName,
}
}
}

export class AmountNotEnoughException extends Error {
public code = ErrorCode.AmountNotEnough
constructor() {
super(`messages.codes.${ErrorCode.AmountNotEnough}`)
}
}

export default undefined

0 comments on commit 223ed3b

Please sign in to comment.