From 3e96c42c4a4e38a555d16b08285ee0d9c51770fd Mon Sep 17 00:00:00 2001 From: Kenneth Date: Sun, 30 Nov 2025 20:08:31 +0000 Subject: [PATCH] fix: handle missing expected err cases --- apps/backend/internal/upload/err.go | 1 + apps/backend/internal/upload/http.go | 9 +++++++++ apps/backend/internal/upload/service.go | 3 +++ 3 files changed, 13 insertions(+) diff --git a/apps/backend/internal/upload/err.go b/apps/backend/internal/upload/err.go index 27fdc66..1d97ff1 100644 --- a/apps/backend/internal/upload/err.go +++ b/apps/backend/internal/upload/err.go @@ -6,4 +6,5 @@ var ( ErrNotFound = errors.New("not found") ErrParentNotDirectory = errors.New("parent is not a directory") ErrConflict = errors.New("node conflict") + ErrContentNotUploaded = errors.New("content has not been uploaded") ) diff --git a/apps/backend/internal/upload/http.go b/apps/backend/internal/upload/http.go index 7052761..3ce4b8a 100644 --- a/apps/backend/internal/upload/http.go +++ b/apps/backend/internal/upload/http.go @@ -55,6 +55,12 @@ func (h *HTTPHandler) Create(c *fiber.Ctx) error { if errors.Is(err, ErrNotFound) { return c.SendStatus(fiber.StatusNotFound) } + if errors.Is(err, ErrParentNotDirectory) { + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Parent is not a directory"}) + } + if errors.Is(err, ErrConflict) { + return c.Status(fiber.StatusConflict).JSON(fiber.Map{"error": "A file with this name already exists"}) + } return httperr.Internal(err) } @@ -102,6 +108,9 @@ func (h *HTTPHandler) Update(c *fiber.Ctx) error { if errors.Is(err, ErrNotFound) { return c.SendStatus(fiber.StatusNotFound) } + if errors.Is(err, ErrContentNotUploaded) { + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Content has not been uploaded"}) + } return httperr.Internal(err) } return c.JSON(upload) diff --git a/apps/backend/internal/upload/service.go b/apps/backend/internal/upload/service.go index 1b88907..aace9c3 100644 --- a/apps/backend/internal/upload/service.go +++ b/apps/backend/internal/upload/service.go @@ -131,6 +131,9 @@ func (s *Service) CompleteUpload(ctx context.Context, db bun.IDB, accountID uuid err := s.vfs.WriteFile(ctx, db, upload.TargetNode, virtualfs.FileContentFromBlobKey(upload.TargetNode.BlobKey)) if err != nil { + if errors.Is(err, blob.ErrNotFound) { + return nil, ErrContentNotUploaded + } return nil, err }