@@ -10,11 +10,13 @@ type Error interface {
1010
1111 Code () int
1212 Message () string
13+ Data () interface {}
1314}
1415
1516type ErrorPayload struct {
16- CodePayload int `json:"code"`
17- MessagePayload string `json:"message"`
17+ CodePayload int `json:"code"`
18+ MessagePayload string `json:"message"`
19+ DataPlayload interface {} `json:"data"`
1820}
1921
2022func New (code int , message string ) Error {
@@ -24,6 +26,14 @@ func New(code int, message string) Error {
2426 }
2527}
2628
29+ func NewWithData (code int , message string , data interface {}) Error {
30+ return ErrorPayload {
31+ CodePayload : code ,
32+ MessagePayload : message ,
33+ DataPlayload : data ,
34+ }
35+ }
36+
2737func NewFromErr (code int , err error ) Error {
2838 return ErrorPayload {
2939 CodePayload : code ,
@@ -35,6 +45,7 @@ func NewErrorPayloadFromError(errx Error) *ErrorPayload {
3545 return & ErrorPayload {
3646 CodePayload : errx .Code (),
3747 MessagePayload : errx .Message (),
48+ DataPlayload : errx .Data (),
3849 }
3950}
4051
@@ -46,8 +57,16 @@ func (thisRef ErrorPayload) Message() string {
4657 return thisRef .MessagePayload
4758}
4859
60+ func (thisRef ErrorPayload ) Data () interface {} {
61+ return thisRef .DataPlayload
62+ }
63+
4964func (thisRef ErrorPayload ) String () string {
50- return fmt .Sprintf ("message: %s, code: %d" , thisRef .MessagePayload , thisRef .CodePayload )
65+ if thisRef .DataPlayload != nil {
66+ return fmt .Sprintf ("code: %d, message: %s, data: %v" , thisRef .CodePayload , thisRef .MessagePayload , thisRef .DataPlayload )
67+ }
68+
69+ return fmt .Sprintf ("code: %d, message: %s" , thisRef .CodePayload , thisRef .MessagePayload )
5170}
5271
5372func (thisRef ErrorPayload ) Error () string {
0 commit comments