From bb95fa9d9fb1dcd5135890d441a3a2e0de9195a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 27 Sep 2022 11:39:10 +0000 Subject: [PATCH] align more OCS error responses with oc10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/polish-ocs-errors.md | 6 ++++++ .../handlers/apps/sharing/shares/shares.go | 4 +--- .../owncloud/ocs/response/response.go | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/polish-ocs-errors.md diff --git a/changelog/unreleased/polish-ocs-errors.md b/changelog/unreleased/polish-ocs-errors.md new file mode 100644 index 0000000000..c0b1c6cc00 --- /dev/null +++ b/changelog/unreleased/polish-ocs-errors.md @@ -0,0 +1,6 @@ +Bugfix: Polish OCS error responses + +We aligned more OCS error responses with oc10 + +https://github.com/cs3org/reva/pull/3279 +https://github.com/owncloud/ocis/issues/1799 diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index ac8a7a37b0..33cbcb6f2c 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -227,11 +227,9 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) { if statRes.Status.Code != rpc.Code_CODE_OK { switch statRes.Status.Code { case rpc.Code_CODE_NOT_FOUND: - response.WriteOCSError(w, r, http.StatusNotFound, "Not found", nil) - w.WriteHeader(http.StatusNotFound) + response.WriteOCSData(w, r, response.MetaPathNotFound, nil, nil) case rpc.Code_CODE_PERMISSION_DENIED: response.WriteOCSError(w, r, http.StatusNotFound, "No share permission", nil) - w.WriteHeader(http.StatusForbidden) default: sublog.Error().Interface("status", statRes.Status).Msg("CreateShare: stat failed") w.WriteHeader(http.StatusInternalServerError) diff --git a/internal/http/services/owncloud/ocs/response/response.go b/internal/http/services/owncloud/ocs/response/response.go index 97ac1c2773..2ad271c418 100644 --- a/internal/http/services/owncloud/ocs/response/response.go +++ b/internal/http/services/owncloud/ocs/response/response.go @@ -112,6 +112,15 @@ type Meta struct { // MetaOK is the default ok response var MetaOK = Meta{Status: "ok", StatusCode: 100, Message: "OK"} +// MetaFailure is a failure response with code 101 +var MetaFailure = Meta{Status: "", StatusCode: 101, Message: "Failure"} + +// MetaInvalidInput is an error response with code 102 +var MetaInvalidInput = Meta{Status: "", StatusCode: 102, Message: "Invalid Input"} + +// MetaForbidden is an error response with code 104 +var MetaForbidden = Meta{Status: "", StatusCode: 104, Message: "Forbidden"} + // MetaBadRequest is used for unknown errors var MetaBadRequest = Meta{Status: "error", StatusCode: 400, Message: "Bad Request"} @@ -124,9 +133,21 @@ var MetaUnauthorized = Meta{Status: "error", StatusCode: 997, Message: "Unauthor // MetaNotFound is returned when trying to access not existing resources var MetaNotFound = Meta{Status: "error", StatusCode: 998, Message: "Not Found"} +// MetaPathNotFound is returned when trying to share not existing resources +var MetaPathNotFound = Meta{Status: "failure", StatusCode: 404, Message: MessagePathNotFound} + // MetaUnknownError is used for unknown errors var MetaUnknownError = Meta{Status: "error", StatusCode: 999, Message: "Unknown Error"} +// MessageUserNotFound is used when a user can not be found +var MessageUserNotFound = "The requested user could not be found" + +// MessageGroupNotFound is used when a group can not be found +var MessageGroupNotFound = "The requested group could not be found" + +// MessagePathNotFound is used when a file or folder can not be found +var MessagePathNotFound = "Wrong path, file/folder doesn't exist" + // WriteOCSSuccess handles writing successful ocs response data func WriteOCSSuccess(w http.ResponseWriter, r *http.Request, d interface{}) { WriteOCSData(w, r, MetaOK, d, nil)