mirror of
https://github.com/rancher/norman.git
synced 2025-09-13 22:01:34 +00:00
Support unwrapping errors to find httperror.APIError
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
|
||||
"github.com/rancher/norman/httperror"
|
||||
@@ -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{
|
||||
|
Reference in New Issue
Block a user