Exception: Booqable::MissingAttribute

Inherits:
NoMethodError
  • Object
show all
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 StandardError code 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 variant try!(: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

Constructor Details

#initialize(attribute_name, resource) ⇒ MissingAttribute

Initialize a new MissingAttribute error

Parameters:

  • attribute_name (Symbol)

    Name of the absent attribute that was read

  • resource (Sawyer::Resource)

    Resource the attribute was read from



448
449
450
# File 'lib/booqable/error.rb', line 448

def initialize(attribute_name, resource)
  super(build_message(attribute_name, resource), attribute_name)
end