diff --git a/internal/http/services/owncloud/ocdav/locks.go b/internal/http/services/owncloud/ocdav/locks.go index e415e6a62d..08bb282a86 100644 --- a/internal/http/services/owncloud/ocdav/locks.go +++ b/internal/http/services/owncloud/ocdav/locks.go @@ -646,16 +646,6 @@ func (s *svc) unlockReference(ctx context.Context, _ http.ResponseWriter, r *htt err := s.LockSystem.Unlock(ctx, time.Now(), ref, t) if err == nil { return http.StatusNoContent, nil - } else { - switch err.(type) { - case errtypes.Aborted, errtypes.Locked: - return http.StatusLocked, err - case errtypes.PermissionDenied: - return http.StatusForbidden, err - case errtypes.PreconditionFailed: - return http.StatusConflict, err - default: - return http.StatusInternalServerError, err - } } + return errtypes.NewHTTPStatusCodeFromErrtype(err), err } diff --git a/pkg/errtypes/errtypes.go b/pkg/errtypes/errtypes.go index 4aff212931..bc87e07984 100644 --- a/pkg/errtypes/errtypes.go +++ b/pkg/errtypes/errtypes.go @@ -350,3 +350,37 @@ func NewErrtypeFromHTTPStatusCode(code int, message string) error { return InternalError(message) } } + +// NewHTTPStatusCodeFromErrtype maps an errtype to an http status +func NewHTTPStatusCodeFromErrtype(err error) int { + switch err.(type) { + case NotFound: + return http.StatusNotFound + case AlreadyExists: + return http.StatusConflict + case NotSupported: + return http.StatusNotImplemented + case NotModified: + return http.StatusNotModified + case InvalidCredentials: + return http.StatusUnauthorized + case PermissionDenied: + return http.StatusForbidden + case Locked: + return http.StatusLocked + case Aborted: + return http.StatusPreconditionFailed + case PreconditionFailed: + return http.StatusMethodNotAllowed + case InsufficientStorage: + return http.StatusInsufficientStorage + case BadRequest: + return http.StatusBadRequest + case PartialContent: + return http.StatusPartialContent + case ChecksumMismatch: + return StatusChecksumMismatch + default: + return http.StatusInternalServerError + } +}