Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2021-12-07 07:06:39 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-12-08 04:21:29 +0300
commitc57f28159a32b325ec54f190b0f13c4676600d42 (patch)
treee546d558ae3f4d133cfeda2a83de29434c7dc019 /internal
parent34190011b2f774bc9a3613850a7be9d67c8ecd7e (diff)
fix: use if statement instead of switch
Diffstat (limited to 'internal')
-rw-r--r--internal/serving/disk/reader.go20
-rw-r--r--internal/vfs/zip/vfs.go15
2 files changed, 20 insertions, 15 deletions
diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go
index 2438daf7..f45c9092 100644
--- a/internal/serving/disk/reader.go
+++ b/internal/serving/disk/reader.go
@@ -277,15 +277,21 @@ func (reader *Reader) serveCustomFile(ctx context.Context, w http.ResponseWriter
}
func handleRootError(err error, h serving.Handler) bool {
- switch err {
- case fs.ErrNotExist:
+ if err == nil {
return false
- case context.Canceled:
+ }
+
+ if errors.Is(err, fs.ErrNotExist) {
+ return false
+ }
+
+ if errors.Is(err, context.Canceled) {
// Handle context.Canceled error as not found exist https://gitlab.com/gitlab-org/gitlab-pages/-/issues/669
- //httperrors.Serve404(h.Writer)
- return true
- default:
- httperrors.Serve500WithRequest(h.Writer, h.Request, "vfs.Root", err)
+ httperrors.Serve404(h.Writer)
return true
}
+
+ httperrors.Serve500WithRequest(h.Writer, h.Request, "vfs.Root", err)
+ return true
+
}
diff --git a/internal/vfs/zip/vfs.go b/internal/vfs/zip/vfs.go
index 4ad1075f..c28ec017 100644
--- a/internal/vfs/zip/vfs.go
+++ b/internal/vfs/zip/vfs.go
@@ -179,14 +179,13 @@ func (zfs *zipVFS) Root(ctx context.Context, path string, cacheKey string) (vfs.
// we do it in loop to not use any additional locks
for {
root, err := zfs.findOrOpenArchive(ctx, cacheKey, path)
- if err != nil {
- switch err {
- case httprange.ErrNotFound:
- // If archive is not found, return a known `vfs` error
- return nil, fs.ErrNotExist
- case errAlreadyCached:
- continue
- }
+ if errors.Is(err, errAlreadyCached) {
+ continue
+ }
+
+ // If archive is not found, return a known `vfs` error
+ if errors.Is(err, httprange.ErrNotFound) {
+ return nil, fs.ErrNotExist
}
return root, err