Skip to content

Commit

Permalink
Merge pull request #374 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Support unwrapping errors to find httperror.APIError
  • Loading branch information
ibuildthecloud authored Jul 28, 2020
2 parents b3163ad + 559ff3e commit 1697d43
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions httperror/handler/handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handler

import (
"errors"
"net/url"

"github.com/rancher/norman/httperror"
Expand All @@ -9,17 +10,16 @@ import (
)

func ErrorHandler(request *types.APIContext, err error) {
var error *httperror.APIError
if apiError, ok := err.(*httperror.APIError); ok {
if apiError.Cause != nil {
error := &httperror.APIError{}
if errors.As(err, &error) {
if error.Cause != nil {
url, _ := url.PathUnescape(request.Request.URL.String())
if url == "" {
url = request.Request.URL.String()
}
logrus.Errorf("API error response %v for %v %v. Cause: %v", apiError.Code.Status, request.Request.Method,
url, apiError.Cause)
logrus.Errorf("API error response %v for %v %v. Cause: %v", error.Code.Status, request.Request.Method,
url, error.Cause)
}
error = apiError
} else {
logrus.Errorf("Unknown error: %v", err)
error = &httperror.APIError{
Expand Down

0 comments on commit 1697d43

Please sign in to comment.