Exception: Booqable::MissingAttribute
- Inherits:
-
NoMethodError
- Object
- NoMethodError
- Booqable::MissingAttribute
- Defined in:
- lib/booqable/error.rb
Overview
Raised when reading an attribute that is absent from an API resource
Sawyer normally answers reads of absent attributes with nil, which turns
typos and renamed API fields (e.g. time_zone vs default_timezone)
into silent data bugs. Resources created by this gem raise this error
instead — see StrictAttributes.
Attributes that are present in the payload with a null value still return nil; only reads of keys that are absent from the payload raise.
This inherits from NoMethodError (not Booqable::Error) because an absent attribute is a programming error in the caller, not an API failure:
- generic
rescue NoMethodError/rescue StandardErrorcode keeps working - ActiveSupport's
resource.try(:foo)stays a safe probe: it returns nil without calling, since respond_to? is false for absent attributes (the bang varianttry!(:foo)raises) - hash-style access stays a lenient, explicit probe:
resource[:foo]returns nil for absent keys because Sawyer rescues NoMethodError there
Instance Method Summary collapse
-
#initialize(attribute_name, resource) ⇒ MissingAttribute
constructor
Initialize a new MissingAttribute error.
Constructor Details
#initialize(attribute_name, resource) ⇒ MissingAttribute
Initialize a new MissingAttribute error
448 449 450 |
# File 'lib/booqable/error.rb', line 448 def initialize(attribute_name, resource) super((attribute_name, resource), attribute_name) end |