Skip to content

Commit

Permalink
feat: better handling of not found and forbidden
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Jan 3, 2024
1 parent 4ff4c73 commit 5a8cd7f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions http/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (s *httpServer) handleIndex(ctx *fiber.Ctx) error {

var err error
files, err = s.storage.ReadDir(".", user)
if err != nil {
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fileshare.ErrStorageReadForbidden) {
return newHttpError(fiber.StatusNotFound, "directory not found", err)
} else if err != nil {
return err
}
}
Expand Down Expand Up @@ -79,7 +81,9 @@ func (s *httpServer) handleFiles(ctx *fiber.Ctx) error {
}

files, err := s.storage.ReadDir(dir, user)
if err != nil {
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fileshare.ErrStorageReadForbidden) {
return newHttpError(fiber.StatusNotFound, "directory not found", err)
} else if err != nil {
return err
}

Expand Down Expand Up @@ -116,7 +120,9 @@ func (s *httpServer) handleDownload(ctx *fiber.Ctx) error {

// open file for stats and eventually reading
file, stat, err := s.storage.OpenFile(path, user)
if err != nil {
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fileshare.ErrStorageReadForbidden) {
return newHttpError(fiber.StatusNotFound, "file not found", err)
} else if err != nil {
return err
}

Expand Down

0 comments on commit 5a8cd7f

Please sign in to comment.