Skip to content

Commit

Permalink
update README with info about param coercion failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Zukowski committed Nov 14, 2015
1 parent bfe9704 commit 06b8d10
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ desc 'Returns your public timeline.' do
description: 'Not really needed',
required: false
}

end
get :public_timeline do
Status.limit(20)
Expand Down Expand Up @@ -751,7 +751,9 @@ Aside from the default set of supported types listed above, any class can be
used as a type so long as an explicit coercion method is supplied. If the type
implements a class-level `parse` method, Grape will use it automatically.
This method must take one string argument and return an instance of the correct
type, or raise an exception to indicate the value was invalid. E.g.,
type. An exception raised inside the `parse` method will be reported as a validation
failure with a generic error message. To report a custom error message, return an
`InvalidValue` initialized with the custom message. E.g.,

```ruby
class Color
Expand All @@ -761,8 +763,11 @@ class Color
end

def self.parse(value)
fail 'Invalid color' unless %w(blue red green).include?(value)
new(value)
if %w(blue red green).include?(value)
new(value)
else
Grape::Validations::Types::InvalidValue.new "is not a valid color"
end
end
end

Expand Down

0 comments on commit 06b8d10

Please sign in to comment.