fix: handle missing expected err cases

This commit is contained in:
2025-11-30 20:08:31 +00:00
parent 6c61cbe1fd
commit 3e96c42c4a
3 changed files with 13 additions and 0 deletions

View File

@@ -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")
)

View File

@@ -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)

View File

@@ -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
}