mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 20:36:12 +02:00
lint: replace "github.com/pkg/errors" in apiserver (#3097)
This commit is contained in:
parent
206211ce53
commit
b081065c8e
2 changed files with 9 additions and 10 deletions
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue