@@ -114,7 +114,10 @@ func (a *App) defaultErrorMiddleware(next Handler) Handler {
114114 if err == nil {
115115 return nil
116116 }
117+
118+ // 500 Internal Server Error by default
117119 status := http .StatusInternalServerError
120+
118121 // unpack root err and check for HTTPError
119122 if errors .Is (err , sql .ErrNoRows ) {
120123 status = http .StatusNotFound
@@ -123,9 +126,18 @@ func (a *App) defaultErrorMiddleware(next Handler) Handler {
123126 if errors .As (err , & h ) {
124127 status = h .Status
125128 }
129+
126130 payload := events.Payload {
127131 "context" : c ,
128132 "app" : a ,
133+ "status" : status ,
134+ "error" : err ,
135+ }
136+ if status >= http .StatusInternalServerError {
137+ // we need the details (or stack trace) only for 5xx errors.
138+ // pkg/errors supports '%+v' for stack trace.
139+ // the other type of errors that support '%+v' is also supported.
140+ payload ["stacktrace" ] = fmt .Sprintf ("%+v" , err )
129141 }
130142 events .EmitError (events .ErrGeneral , err , payload )
131143
@@ -190,7 +202,7 @@ func defaultErrorHandler(status int, origErr error, c Context) error {
190202 }
191203 }
192204
193- trace := origErr . Error ( )
205+ trace := fmt . Sprintf ( "%+v" , origErr )
194206 if cause := errors .Unwrap (origErr ); cause != nil {
195207 origErr = cause
196208 }
@@ -269,5 +281,5 @@ func (i inspectHeaders) String() string {
269281 bb = append (bb , fmt .Sprintf ("%s: %s" , k , v ))
270282 }
271283 sort .Strings (bb )
272- return strings .Join (bb , "\n \n " )
284+ return strings .Join (bb , "\n " )
273285}
0 commit comments