Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align more OCS error responses with oc10 #3279

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/polish-ocs-errors.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions internal/http/services/owncloud/ocs/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -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)
Expand Down