File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -408,7 +408,7 @@ desc 'Returns your public timeline.' do
408
408
description: ' Not really needed' ,
409
409
required: false
410
410
}
411
-
411
+
412
412
end
413
413
get :public_timeline do
414
414
Status .limit(20 )
@@ -751,7 +751,9 @@ Aside from the default set of supported types listed above, any class can be
751
751
used as a type so long as an explicit coercion method is supplied. If the type
752
752
implements a class-level ` parse ` method, Grape will use it automatically.
753
753
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.,
755
757
756
758
``` ruby
757
759
class Color
@@ -761,8 +763,11 @@ class Color
761
763
end
762
764
763
765
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
766
771
end
767
772
end
768
773
You can’t perform that action at this time.
0 commit comments