diff --git a/api/handler/list.go b/api/handler/list.go index 9b68bcd4f..2642ecf2a 100644 --- a/api/handler/list.go +++ b/api/handler/list.go @@ -45,11 +45,7 @@ func (h *handler) registerAndSendError(w http.ResponseWriter, r *http.Request, e zap.String("request_id", rid), zap.Error(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) } // ListBucketsHandler handles bucket listing requests. diff --git a/api/handler/put.go b/api/handler/put.go index 834fb3a0d..a70566dd8 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -87,7 +87,6 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { var ( err error p = layer.CreateBucketParams{} - rid = api.GetRequestID(r.Context()) req = mux.Vars(r) ) p.Name = req["bucket"] @@ -98,19 +97,19 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { } if err != nil { - h.writeError(w, r, "could not parse basic ACL", rid, err) + h.registerAndSendError(w, r, err, "could not parse basic ACL") return } createParams, err := parseLocationConstraint(r) if err != nil { - h.writeError(w, r, "could not parse body", rid, err) + h.registerAndSendError(w, r, err, "could not parse body") return } boxData, err := getBoxData(r.Context()) if err != nil { - h.writeError(w, r, "could get boxData", rid, err) + h.registerAndSendError(w, r, err, "could not get boxData") return } @@ -125,14 +124,14 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { if p.Policy == nil { p.Policy, err = policy.Parse(defaultPolicy) if err != nil { - h.writeError(w, r, "could not parse policy", rid, err) + h.registerAndSendError(w, r, err, "could not parse policy") return } } cid, err := h.obj.CreateBucket(r.Context(), &p, boxData) if err != nil { - h.writeError(w, r, "could not create bucket", rid, err) + h.registerAndSendError(w, r, err, "could not create bucket") return } @@ -174,11 +173,6 @@ func parseBasicACL(basicACL string) (uint32, error) { } } -func (h *handler) writeError(w http.ResponseWriter, r *http.Request, msg, rid string, err error) { - h.log.Error(msg, zap.String("request_id", rid), zap.Error(err)) - api.WriteErrorResponse(r.Context(), w, err, r.URL) -} - func getBoxData(ctx context.Context) (*accessbox.Box, error) { var boxData *accessbox.Box data, ok := ctx.Value(api.BoxData).(*accessbox.Box)