mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-17 15:01:20 +02:00
* tests: don't run crowdsec if not necessary * make listen_uri report the random port number when 0 is requested * move apiserver.getTLSAuthType() -> csconfig.TLSCfg.GetAuthType() * move apiserver.isEnrolled() -> apiclient.ApiClient.IsEnrolled() * extract function apiserver.recoverFromPanic() * simplify and move APIServer.GetTLSConfig() -> TLSCfg.GetTLSConfig() * moved TLSCfg type to csconfig/tls.go * APIServer.InitController(): early return / happy path * extract function apiserver.newGinLogger() * lapi tests * update unit test * lint (testify) * lint (whitespace, variable names) * update docker tests
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package v1
|
|
|
|
import (
|
|
"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:
|
|
gctx.JSON(http.StatusNotFound, gin.H{"message": err.Error()})
|
|
return
|
|
case database.UserExists:
|
|
gctx.JSON(http.StatusForbidden, gin.H{"message": err.Error()})
|
|
return
|
|
case database.HashError:
|
|
gctx.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
|
|
return
|
|
case database.InsertFail:
|
|
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
|
return
|
|
case database.QueryFail:
|
|
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
|
return
|
|
case database.ParseTimeFail:
|
|
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
|
return
|
|
case database.ParseDurationFail:
|
|
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
|
return
|
|
default:
|
|
gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
|
return
|
|
}
|
|
}
|