fix(caldav): return other status codes than 500 when projects are not found (#3065)

This allows CalDav clients to behave properly. In particular, DavX5 will error out on syncing the collections list rather than removing deleted projects from its local cache.

Resolves: https://community.vikunja.io/t/deleting-a-project-breaks-caldav/3315/3
Co-authored-by: Janne Heß <janne@hess.ooo>
Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/3065
Reviewed-by: konrad <k@knt.li>
Co-authored-by: das_j <das_j@noreply.kolaente.dev>
Co-committed-by: das_j <das_j@noreply.kolaente.dev>
This commit is contained in:
das_j
2025-02-06 12:38:27 +00:00
committed by konrad
parent c31f84d71e
commit 989a40ad42

View File

@@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io"
"net/http"
"reflect"
"strconv"
"strings"
@@ -46,6 +47,9 @@ func getBasicAuthUserFromContext(c echo.Context) (*user.User, error) {
// ProjectHandler returns all tasks from a project
func ProjectHandler(c echo.Context) error {
project, err := getProjectFromParam(c)
if err != nil && models.IsErrProjectDoesNotExist(err) {
return c.String(http.StatusNotFound, "Project not found")
}
if err != nil {
return err
}
@@ -69,7 +73,8 @@ func ProjectHandler(c echo.Context) error {
if vtodo != "" && strings.HasPrefix(vtodo, `BEGIN:VCALENDAR`) {
storage.task, err = caldav2.ParseTaskFromVTODO(vtodo)
if err != nil {
return echo.ErrInternalServerError.SetInternal(err)
log.Warningf("[CALDAV] Failed to parse task: %v", err)
return models.ErrInvalidData{Message: "Invalid task"}
}
}