File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,10 @@ func (e *respError) ErrorData() interface{} {
8484 return e .Data
8585}
8686
87- var marshalableRT = reflect .TypeOf (new (marshalable )).Elem ()
87+ var (
88+ marshalableRT = reflect .TypeOf (new (marshalable )).Elem ()
89+ errorsRT = reflect .TypeOf (new (ErrorWithData )).Elem ()
90+ )
8891
8992func (e * respError ) val (errors * Errors ) reflect.Value {
9093 if errors != nil {
@@ -96,9 +99,23 @@ func (e *respError) val(errors *Errors) reflect.Value {
9699 } else {
97100 v = reflect .New (t )
98101 }
102+
99103 if len (e .Meta ) > 0 && v .Type ().Implements (marshalableRT ) {
100104 _ = v .Interface ().(marshalable ).UnmarshalJSON (e .Meta )
105+ } else {
106+ msgField := v .Elem ().FieldByName ("Message" )
107+ if msgField .IsValid () && msgField .CanSet () && msgField .Kind () == reflect .String {
108+ msgField .SetString (e .Message )
109+ }
110+
111+ if v .Type ().Implements (errorsRT ) {
112+ dataField := v .Elem ().FieldByName ("Data" )
113+ if dataField .IsValid () && dataField .CanSet () {
114+ dataField .Set (reflect .ValueOf (e .Data ))
115+ }
116+ }
101117 }
118+
102119 if t .Kind () != reflect .Ptr {
103120 v = v .Elem ()
104121 }
You can’t perform that action at this time.
0 commit comments