fix wrong error code on wrapped status errors
This commit is contained in:
parent
f06abb1f02
commit
837e146b2b
2 changed files with 24 additions and 1 deletions
|
@ -78,7 +78,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if rsp.Status == 0 {
|
||||
if rsp.Error != nil {
|
||||
if statusError, ok := rsp.Error.(StatusError); ok {
|
||||
ogErr := errors.Unwrap(rsp.Error)
|
||||
if statusError, ok := ogErr.(StatusError); ok {
|
||||
rsp.Status = statusError.Status
|
||||
} else {
|
||||
rsp.Status = http.StatusInternalServerError
|
||||
|
|
|
@ -41,6 +41,28 @@ func Wrap(err interface{}, skip int) *errors.Error {
|
|||
return errors.Wrap(err, skip+1)
|
||||
}
|
||||
|
||||
// Unwrap returns the original error that was wrapped
|
||||
func Unwrap(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
deeper := true
|
||||
for deeper {
|
||||
deeper = false
|
||||
if e, ok := err.(*errors.Error); ok {
|
||||
err = e.Err
|
||||
deeper = true
|
||||
}
|
||||
if c, ok := err.(causer); ok {
|
||||
err = c.Cause()
|
||||
deeper = true
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Is compares two wrapped errors to determine if the underlying errors are the same
|
||||
// It also interops with errors from pkg/errors
|
||||
func Is(e error, original error) bool {
|
||||
|
|
Loading…
Add table
Reference in a new issue