[#155] Fix error handling
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
1ecf32c302
commit
f2eeed0b85
3 changed files with 3 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue