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

return correct status code for api v2 #711

Merged
merged 1 commit into from
May 5, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ const (
PermissionAll Permissions = (1 << (iota - 1)) - 1
)

var (
// ErrPermissionAboveRange defines a permission specific error.
ErrPermissionAboveRange = fmt.Errorf("The provided permission is higher than %d", PermissionAll)
)

// NewPermissions creates a new Permissions instanz.
// The value must be in the valid range.
func NewPermissions(val int) (Permissions, error) {
if val <= int(PermissionInvalid) || int(PermissionAll) < val {
if val <= int(PermissionInvalid) {
return PermissionInvalid, fmt.Errorf("permissions %d out of range %d - %d", val, PermissionRead, PermissionAll)
} else if int(PermissionAll) < val {
return PermissionInvalid, ErrPermissionAboveRange
}
return Permissions(val), nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ func (h *Handler) createShare(w http.ResponseWriter, r *http.Request) {
}
permissions, err = conversions.NewPermissions(pint)
if err != nil {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, err.Error(), nil)
if err == conversions.ErrPermissionAboveRange {
response.WriteOCSError(w, r, http.StatusNotFound, err.Error(), nil)
} else {
response.WriteOCSError(w, r, response.MetaBadRequest.StatusCode, err.Error(), nil)
}
return
}
role = conversions.Permissions2Role(permissions)
Expand Down