From 0d0a46e5e10c7c9799f4e20465b37da0ca915c2d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 9 Jun 2023 07:57:06 -0400 Subject: [PATCH] refactor: use errors.Is and gorm.ErrRecordNotFound --- tus/tus.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tus/tus.go b/tus/tus.go index 68183e8..f953aa7 100644 --- a/tus/tus.go +++ b/tus/tus.go @@ -17,6 +17,7 @@ import ( "github.com/tus/tusd/pkg/memorylocker" "go.uber.org/zap" "golang.org/x/exp/slices" + "gorm.io/gorm" "io" ) @@ -52,7 +53,7 @@ func Init() *tusd.Handler { var upload model.Upload result := db.Get().Where(&model.Upload{Hash: hash}).First(&upload) - if (result.Error != nil && result.Error.Error() != "record not found") || result.RowsAffected > 0 { + if (result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound)) || result.RowsAffected > 0 { hashBytes, err := hex.DecodeString(hash) if err != nil { logger.Get().Debug("invalid hash", zap.Error(err))