Skip to content

Commit

Permalink
validate error
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 23, 2022
1 parent 00243cf commit 58fb53b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func (c *DefaultCtx) BindWithValidate(v any) error {
}

func (c *DefaultCtx) Validate(v any) error {
if c.app.config.Validator == nil {
return NilValidatorError{}
}
return c.app.config.Validator.Validate(v)
}

Expand Down
8 changes: 8 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ var (
ErrRangeUnsatisfiable = errors.New("range: unsatisfiable range")
)

// NilValidatorError is the validate error when context.Validate is called but no validator is set in config.
type NilValidatorError struct {
}

func (n NilValidatorError) Error() string {
return "fiber: ctx.Validate(v any) is called without validator"
}

// InvalidBinderError is the error when try to bind unsupported type.
type InvalidBinderError struct {
Type reflect.Type
Expand Down

0 comments on commit 58fb53b

Please sign in to comment.