[#155] Fix error handling

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-14 19:06:24 +03:00
parent 1ecf32c302
commit f2eeed0b85
3 changed files with 3 additions and 15 deletions

View file

@ -1633,7 +1633,7 @@ func GetAPIError(code ErrorCode) Error {
// getErrorResponse gets in standard error and resource value and // getErrorResponse gets in standard error and resource value and
// provides a encodable populated response values. // provides a encodable populated response values.
func getAPIErrorResponse(ctx context.Context, err error, resource, requestID, hostID string) ErrorResponse { func getAPIErrorResponse(ctx context.Context, err error, resource, requestID, hostID string) ErrorResponse {
code := "BadRequest" code := "InternalError"
desc := err.Error() desc := err.Error()
info := GetReqInfo(ctx) info := GetReqInfo(ctx)

View file

@ -2,7 +2,6 @@ package handler
import ( import (
"encoding/xml" "encoding/xml"
"errors"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -120,18 +119,7 @@ func (h *handler) listObjects(w http.ResponseWriter, r *http.Request) (*listObje
zap.String("request_id", rid), zap.String("request_id", rid),
zap.Error(err)) zap.Error(err))
var s3Err api.Error api.WriteErrorResponse(r.Context(), w, err, r.URL)
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)
return nil, nil, err return nil, nil, err
} }

View file

@ -119,7 +119,7 @@ var s3ErrorResponseMap = map[string]string{
// WriteErrorResponse writes error headers. // WriteErrorResponse writes error headers.
func WriteErrorResponse(ctx context.Context, w http.ResponseWriter, err error, reqURL *url.URL) { 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 { if e, ok := err.(Error); ok {
code = e.HTTPStatusCode code = e.HTTPStatusCode