From 0039fe40236464496c8c8c499ca94b1364bb6e0b Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 26 Nov 2024 13:56:41 +1300 Subject: [PATCH] cmd: fix object lock invalid error codes to match AWS Updates storj/edge#510 Updates storj/edge#511 Change-Id: I50f754983ae6d058b6514fd55df2a9daa25eff18 --- cmd/api-errors.go | 8 ++++---- cmd/object-handlers.go | 4 +--- pkg/bucket/object/lock/lock.go | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/api-errors.go b/cmd/api-errors.go index 674b0a1fa3c9b..c2fae9a39ebac 100644 --- a/cmd/api-errors.go +++ b/cmd/api-errors.go @@ -944,13 +944,13 @@ var errorCodes = errorCodeMap{ HTTPStatusCode: http.StatusBadRequest, }, ErrPastObjectLockRetainDate: { - Code: "InvalidRequest", - Description: "the retain until date must be in the future", + Code: "InvalidArgument", + Description: "The retain until date must be in the future", HTTPStatusCode: http.StatusBadRequest, }, ErrUnknownWORMModeDirective: { - Code: "InvalidRequest", - Description: "unknown wormMode directive", + Code: "InvalidArgument", + Description: "Unknown wormMode directive", HTTPStatusCode: http.StatusBadRequest, }, ErrObjectLockInvalidHeaders: { diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 87657863b5da8..349cd954d0fa5 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -3134,9 +3134,7 @@ func (api ObjectAPIHandlers) PutObjectRetentionHandler(w http.ResponseWriter, r objRetention, err := objectlock.ParseObjectRetention(r.Body) if err != nil { - apiErr := errorCodes.ToAPIErr(ErrMalformedXML) - apiErr.Description = err.Error() - WriteErrorResponse(ctx, w, apiErr, r.URL, guessIsBrowserReq(r)) + WriteErrorResponse(ctx, w, ToAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) return } diff --git a/pkg/bucket/object/lock/lock.go b/pkg/bucket/object/lock/lock.go index 2ed40d7135508..68c8617ef7d14 100644 --- a/pkg/bucket/object/lock/lock.go +++ b/pkg/bucket/object/lock/lock.go @@ -346,7 +346,7 @@ func ParseObjectRetention(reader io.Reader) (*ObjectRetention, error) { return nil, err } if ret.Mode != "" && !ret.Mode.Valid() { - return &ret, ErrUnknownWORMModeDirective + return &ret, ErrMalformedXML } if ret.Mode.Valid() && ret.RetainUntilDate.IsZero() {