Skip to content

Commit 9c4b3ad

Browse files
authored
Merge pull request #13 from objenious/go/std_unwrap_error
use standard error unwrap for cause
2 parents f861e14 + 8cfb3d6 commit 9c4b3ad

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

http.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package errorutil
22

3-
import "net/http"
3+
import (
4+
"errors"
5+
"net/http"
6+
)
47

58
// HTTPStatusCodeEr defines errors that should return a specific HTTP status code
69
type HTTPStatusCodeEr interface {
@@ -55,10 +58,11 @@ func HTTPStatusCode(err error) int {
5558
return http.StatusRequestTimeout
5659
}
5760
cause, ok := err.(causer)
58-
if !ok {
59-
break
61+
if ok {
62+
err = cause.Cause()
63+
} else {
64+
err = errors.Unwrap(err)
6065
}
61-
err = cause.Cause()
6266
}
6367
return http.StatusInternalServerError
6468
}

0 commit comments

Comments
 (0)