lint: replace "github.com/pkg/errors" in apiserver (#3097)

This commit is contained in:
mmetc 2024-07-01 11:54:49 +02:00 committed by GitHub
parent 206211ce53
commit b081065c8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View file

@ -48,7 +48,6 @@ linters-settings:
desc: "errors.Wrap() is deprecated in favor of fmt.Errorf()"
files:
- "!**/pkg/database/*.go"
- "!**/pkg/apiserver/controllers/v1/errors.go"
yaml:
files:
- "!**/pkg/acquisition/acquisition.go"

View file

@ -1,35 +1,35 @@
package v1
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/crowdsecurity/crowdsec/pkg/database"
)
func (c *Controller) HandleDBErrors(gctx *gin.Context, err error) {
switch errors.Cause(err) {
case database.ItemNotFound:
switch {
case errors.Is(err, database.ItemNotFound):
gctx.JSON(http.StatusNotFound, gin.H{"message": err.Error()})
return
case database.UserExists:
case errors.Is(err, database.UserExists):
gctx.JSON(http.StatusForbidden, gin.H{"message": err.Error()})
return
case database.HashError:
case errors.Is(err, database.HashError):
gctx.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
return
case database.InsertFail:
case errors.Is(err, database.InsertFail):
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
case database.QueryFail:
case errors.Is(err, database.QueryFail):
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
case database.ParseTimeFail:
case errors.Is(err, database.ParseTimeFail):
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
case database.ParseDurationFail:
case errors.Is(err, database.ParseDurationFail):
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
default: