-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.go
62 lines (50 loc) · 1.02 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package core
import (
"fmt"
"github.com/go-errors/errors"
)
type IError interface {
Error() string
GetCode() string
GetStatus() int
JSON() interface{}
OriginalError() error
GetMessage() interface{}
}
type Error struct {
Status int `json:"-"`
Code string `json:"code"`
Message interface{} `json:"message"`
Data interface{} `json:"-"`
Fields interface{} `json:"fields,omitempty"`
originalError error
}
func (c Error) JSON() interface{} {
return c
}
func (c Error) Error() string {
return fmt.Sprintf("code : %v message : %v", c.Code, c.Message)
}
func (c Error) GetCode() string {
return c.Code
}
func (c Error) GetStatus() int {
return c.Status
}
func (c Error) OriginalError() error {
if c.originalError == nil {
return c
}
return c.originalError
}
func (c Error) GetMessage() interface{} {
return c.Message
}
func Recover(textError string) {
if r := recover(); r != nil {
panic(textError)
}
}
func Crash(err error) error {
return errors.New(err)
}