Module: Taro::Types::Shared::Errors

Defined in:
lib/taro/types/shared/errors.rb

Instance Method Summary collapse

Instance Method Details

#coerce_error_message(msg, value) ⇒ Object



10
11
12
13
14
# File 'lib/taro/types/shared/errors.rb', line 10

def coerce_error_message(msg, value)
  type_class = is_a?(Taro::Types::Field) ? self.type : self.class
  type_desc = type_class.name.sub(/^Taro::Types::.*?([^:]+)$/, '\1')
  "#{value.class} is not valid as #{type_desc}: #{msg}"
end

#input_error(msg, value = object) ⇒ Object

Raises:



2
3
4
# File 'lib/taro/types/shared/errors.rb', line 2

def input_error(msg, value = object)
  raise Taro::InputError.new(coerce_error_message(msg, value), value, self)
end

#response_error(msg, value = object) ⇒ Object



6
7
8
# File 'lib/taro/types/shared/errors.rb', line 6

def response_error(msg, value = object)
  raise Taro::ResponseError.new(coerce_error_message(msg, value), value, self)
end