forked from TrueCloudLab/frostfs-s3-gw
[#184] Unify error handling
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
6674e350cc
commit
f4c29cd300
17 changed files with 196 additions and 541 deletions
|
@ -3,40 +3,18 @@ package handler
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (h *handler) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
bkt = mux.Vars(r)["bucket"]
|
||||
rid = api.GetRequestID(r.Context())
|
||||
)
|
||||
|
||||
if _, err := h.obj.GetBucketInfo(r.Context(), bkt); err != nil {
|
||||
h.log.Error("something went wrong",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
|
||||
api.WriteErrorResponse(r.Context(), w, api.Error{
|
||||
Code: api.GetAPIError(api.ErrInternalError).Code,
|
||||
Description: err.Error(),
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
|
||||
return
|
||||
} else if err = api.EncodeToResponse(w, LocationResponse{Location: ""}); err != nil {
|
||||
h.log.Error("could not write response",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
|
||||
api.WriteErrorResponse(r.Context(), w, api.Error{
|
||||
Code: api.GetAPIError(api.ErrInternalError).Code,
|
||||
Description: err.Error(),
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
reqInfo := api.GetReqInfo(r.Context())
|
||||
|
||||
if _, err := h.obj.GetBucketInfo(r.Context(), reqInfo.BucketName); err != nil {
|
||||
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := api.EncodeToResponse(w, LocationResponse{Location: ""}); err != nil {
|
||||
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue