Skip to content

Commit

Permalink
fix: fix misuse of switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Claude-Zq committed Jul 29, 2024
1 parent 231bdf8 commit feb5a2b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions middleware/csrf/custom_errorfunc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ var (
// myErrFunc is executed when an error occurs in csrf middleware.
func myErrFunc(_ context.Context, ctx *app.RequestContext) {
err := ctx.Errors.Last()
switch err {
case errMissingForm, errMissingParam, errMissingHeader, errMissingQuery:
if err == nil {
return
}

if errors.Is(err, errMissingForm) || errors.Is(err, errMissingParam) || errors.Is(err, errMissingHeader) || errors.Is(err, errMissingQuery) {
ctx.String(http.StatusBadRequest, err.Error()) // extract csrf-token failed
case errMissingSalt:
} else if errors.Is(err, errMissingSalt) {
fmt.Println(err.Error())
ctx.String(http.StatusInternalServerError, err.Error()) // get salt failed,which is unexpected
case errInvalidToken:
ctx.String(http.StatusInternalServerError, err.Error()) // get salt failed, which is unexpected
} else if errors.Is(err, errInvalidToken) {
ctx.String(http.StatusBadRequest, err.Error()) // csrf-token is invalid
}
ctx.Abort()
Expand Down

0 comments on commit feb5a2b

Please sign in to comment.