From f2eeed0b858541af9304c73f5513e6dc4a67f236 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 14 Jul 2021 19:06:24 +0300 Subject: [PATCH] [#155] Fix error handling Signed-off-by: Denis Kirillov --- api/errors.go | 2 +- api/handler/list.go | 14 +------------- api/response.go | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/api/errors.go b/api/errors.go index a619193f..4a7648a1 100644 --- a/api/errors.go +++ b/api/errors.go @@ -1633,7 +1633,7 @@ func GetAPIError(code ErrorCode) Error { // getErrorResponse gets in standard error and resource value and // provides a encodable populated response values. func getAPIErrorResponse(ctx context.Context, err error, resource, requestID, hostID string) ErrorResponse { - code := "BadRequest" + code := "InternalError" desc := err.Error() info := GetReqInfo(ctx) diff --git a/api/handler/list.go b/api/handler/list.go index 42435979..9b68bcd4 100644 --- a/api/handler/list.go +++ b/api/handler/list.go @@ -2,7 +2,6 @@ package handler import ( "encoding/xml" - "errors" "net/http" "strconv" "time" @@ -120,18 +119,7 @@ func (h *handler) listObjects(w http.ResponseWriter, r *http.Request) (*listObje zap.String("request_id", rid), zap.Error(err)) - var s3Err api.Error - if ok := errors.As(err, &s3Err); ok { - api.WriteErrorResponse(r.Context(), w, s3Err, r.URL) - return nil, nil, err - } - - api.WriteErrorResponse(r.Context(), w, api.Error{ - Code: api.GetAPIError(api.ErrBadRequest).Code, - Description: err.Error(), - HTTPStatusCode: http.StatusBadRequest, - }, r.URL) - + api.WriteErrorResponse(r.Context(), w, err, r.URL) return nil, nil, err } diff --git a/api/response.go b/api/response.go index 88b961d6..f739198c 100644 --- a/api/response.go +++ b/api/response.go @@ -119,7 +119,7 @@ var s3ErrorResponseMap = map[string]string{ // WriteErrorResponse writes error headers. func WriteErrorResponse(ctx context.Context, w http.ResponseWriter, err error, reqURL *url.URL) { - code := http.StatusBadRequest + code := http.StatusInternalServerError if e, ok := err.(Error); ok { code = e.HTTPStatusCode