Skip to content

Commit 18c27b5

Browse files
committed
Update readme with fail_fast option info
1 parent 8bfd1eb commit 18c27b5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,23 @@ subject.rescue_from Grape::Exceptions::ValidationErrors do |e|
13551355
end
13561356
```
13571357

1358+
Grape returns all validation and coercion errors found by default. To skip all subsequent validation checks when a specific param is found invalid, use `fail_fast: true`.
1359+
For example:
1360+
```ruby
1361+
params do
1362+
required :beer, fail_fast: true
1363+
required :wine
1364+
end
1365+
```
1366+
will not check if `:wine` is present unless it finds `:beer`. The result of empty params would be a single `Grape::Exceptions::ValidationErrors` error.
1367+
Similarly
1368+
```ruby
1369+
params do
1370+
required :blah, allow_blank: false, regexp: /blah/, fail_fast: true
1371+
end
1372+
```
1373+
will not check if the `:blah` matches the regular expression if it is blank.
1374+
13581375
### I18n
13591376

13601377
Grape supports I18n for parameter-related error messages, but will fallback to English if

0 commit comments

Comments
 (0)