File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ type APIException interface {
77 error
88 ErrorCode () int
99 Meta () interface {}
10+ Data () interface {}
1011 Is (code int ) bool
1112 Namespace () string
1213 Reason () string
@@ -34,6 +35,7 @@ type exception struct {
3435 reason string
3536 message string
3637 meta interface {}
38+ data interface {}
3739}
3840
3941func (e * exception ) Error () string {
@@ -55,6 +57,15 @@ func (e *exception) Meta() interface{} {
5557 return e .meta
5658}
5759
60+ func (e * exception ) WithData (d interface {}) APIException {
61+ e .data = d
62+ return e
63+ }
64+
65+ func (e * exception ) Data () interface {} {
66+ return e .data
67+ }
68+
5869func (e * exception ) Is (code int ) bool {
5970 return e .ErrorCode () == code
6071}
Original file line number Diff line number Diff line change @@ -15,12 +15,14 @@ func Failed(w http.ResponseWriter, err error) {
1515 httpCode int
1616 ns string
1717 reason string
18+ data interface {}
1819 )
1920
2021 switch t := err .(type ) {
2122 case exception.APIException :
2223 errCode = t .ErrorCode ()
2324 reason = t .Reason ()
25+ data = t .Data ()
2426 ns = t .Namespace ()
2527 default :
2628 errCode = exception .UnKnownException
@@ -39,6 +41,7 @@ func Failed(w http.ResponseWriter, err error) {
3941 Namespace : ns ,
4042 Reason : reason ,
4143 Message : err .Error (),
44+ Data : data ,
4245 }
4346
4447 // set response heanders
You can’t perform that action at this time.
0 commit comments