Skip to content

Commit 06b8d10

Browse files
author
Matt Zukowski
committed
update README with info about param coercion failures
1 parent bfe9704 commit 06b8d10

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ desc 'Returns your public timeline.' do
408408
description: 'Not really needed',
409409
required: false
410410
}
411-
411+
412412
end
413413
get :public_timeline do
414414
Status.limit(20)
@@ -751,7 +751,9 @@ Aside from the default set of supported types listed above, any class can be
751751
used as a type so long as an explicit coercion method is supplied. If the type
752752
implements a class-level `parse` method, Grape will use it automatically.
753753
This method must take one string argument and return an instance of the correct
754-
type, or raise an exception to indicate the value was invalid. E.g.,
754+
type. An exception raised inside the `parse` method will be reported as a validation
755+
failure with a generic error message. To report a custom error message, return an
756+
`InvalidValue` initialized with the custom message. E.g.,
755757

756758
```ruby
757759
class Color
@@ -761,8 +763,11 @@ class Color
761763
end
762764

763765
def self.parse(value)
764-
fail 'Invalid color' unless %w(blue red green).include?(value)
765-
new(value)
766+
if %w(blue red green).include?(value)
767+
new(value)
768+
else
769+
Grape::Validations::Types::InvalidValue.new "is not a valid color"
770+
end
766771
end
767772
end
768773

0 commit comments

Comments
 (0)