mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
fix: handle missing expected err cases
This commit is contained in:
@@ -6,4 +6,5 @@ var (
|
|||||||
ErrNotFound = errors.New("not found")
|
ErrNotFound = errors.New("not found")
|
||||||
ErrParentNotDirectory = errors.New("parent is not a directory")
|
ErrParentNotDirectory = errors.New("parent is not a directory")
|
||||||
ErrConflict = errors.New("node conflict")
|
ErrConflict = errors.New("node conflict")
|
||||||
|
ErrContentNotUploaded = errors.New("content has not been uploaded")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ func (h *HTTPHandler) Create(c *fiber.Ctx) error {
|
|||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, ErrNotFound) {
|
||||||
return c.SendStatus(fiber.StatusNotFound)
|
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)
|
return httperr.Internal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +108,9 @@ func (h *HTTPHandler) Update(c *fiber.Ctx) error {
|
|||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, ErrNotFound) {
|
||||||
return c.SendStatus(fiber.StatusNotFound)
|
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 httperr.Internal(err)
|
||||||
}
|
}
|
||||||
return c.JSON(upload)
|
return c.JSON(upload)
|
||||||
|
|||||||
@@ -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))
|
err := s.vfs.WriteFile(ctx, db, upload.TargetNode, virtualfs.FileContentFromBlobKey(upload.TargetNode.BlobKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, blob.ErrNotFound) {
|
||||||
|
return nil, ErrContentNotUploaded
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user