Skip to content
This repository was archived by the owner on Apr 22, 2019. It is now read-only.
This repository was archived by the owner on Apr 22, 2019. It is now read-only.

Creating resource doesn't handle UnknownResponse error correctly #15

@niborg

Description

@niborg

Was trying to create a resource, e.g.,

api.contacts.new(contact_params).save

Was receiving this error:

NoMethodError: undefined method `to_i' for false:FalseClass
Did you mean?  to_s
	from /app/vendor/bundle/ruby/2.3.0/gems/clio_client-0.1.9/lib/clio_client/resource.rb:164:in `convert_attribute'
	from /app/vendor/bundle/ruby/2.3.0/gems/clio_client-0.1.9/lib/clio_client/resource.rb:55:in `block (2 levels) in set_attributes'
	from /app/vendor/bundle/ruby/2.3.0/gems/clio_client-0.1.9/lib/clio_client/resource.rb:113:in `save'
	from (irb):28

Turns out, there was an error in our code where we were accidentally populating the 'id' field of one of the contact's phone numbers, so Clio was returning a 'conflict' error which ClioClient initially manifests with a Net::HTTPConflict error. This error is rescued in http.rb and ClioClient::UnknownResponse is thrown in its place.

Then crudable.rb rescues UnknownResponse and returns false.

Where it appears to go wrong is in resource.rb:

def save
  if self.id.nil?
    saved_item = api.create(self.to_params)
    self.id = saved_item && saved_item.id # Trying to assign 'false' to the 'id' attribute
    self
  else
    api.update(self.id, self.to_params)
    self
  end
end

I can make a PR with some guidance on the expected behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions