Skip to content

Commit 3118138

Browse files
committed
[patch] added new helper functions ErrWithoutTrace, Message, HTTPStatusCode
1 parent c304a49 commit 3118138

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

helper.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,32 @@ func HTTPStatusCodeMessage(err error) (int, string, bool) {
356356
return http.StatusInternalServerError, err.Error(), false
357357
}
358358

359+
// ErrWithoutTrace is a duplicate of Message, but with clearer name. The boolean is 'true' if the
360+
// provided err is of type *Error
361+
func ErrWithoutTrace(err error) (string, bool) {
362+
return Message(err)
363+
}
364+
365+
// Message recursively concatenates all the messages set while creating/wrapping the errors. The boolean
366+
// is 'true' if the provided error is of type *Err
367+
func Message(err error) (string, bool) {
368+
derr, _ := err.(*Error)
369+
if derr != nil {
370+
return derr.Message(), true
371+
}
372+
return "", false
373+
}
374+
375+
// HTTPStatusCode returns appropriate HTTP response status code based on type of the error. The boolean
376+
// is 'true' if the provided error is of type *Err
377+
func HTTPStatusCode(err error) (int, bool) {
378+
derr, _ := err.(*Error)
379+
if derr != nil {
380+
return derr.HTTPStatusCode(), true
381+
}
382+
return 0, false
383+
}
384+
359385
// WriteHTTP is a convenience method which will check if the error is of type *Error and
360386
// respond appropriately
361387
func WriteHTTP(err error, w http.ResponseWriter) {

0 commit comments

Comments
 (0)