beezwax/fmrest-ruby

Error thrown for count where api responds with no records matching

leehericks opened this issue · 7 comments

I imagine this bubbles back to FileMaker's API choices, but if I want to query something and find the count, I can never get a count of zero because an error is thrown telling me there are no records.

FmRest::APIError::ParameterError (FileMaker Data API responded with error 401: No records match the request)

I don't want to check for this error in every place that I just want a 0 returned.

What do you think about the count method catching this error to return 0 because this is expected behavior in the application space?

I am currently extending every model from this Record parent to resolve the issue within the models but simply using the scopes finished with .count isn't covered...

class FileMaker::Record < FmRest::Spyke::Base

  def self.find(id)
    query(fm_id: id).find_one
  rescue FmRest::APIError::ParameterError => error
    raise unless error.code == 401
    nil
  end

  def find_one(query)
    query.find_one
  rescue FmRest::APIError::ParameterError => error
    raise unless error.code == 401
    nil
  end

  def find_some(query)
    query.find_some
  rescue FmRest::APIError::ParameterError => error
    raise unless error.code == 401
    []
  end

  def count(query)
    query.count
  rescue FmRest::APIError::ParameterError => error
    raise unless error.code == 401
    0
  end
end
pilaf commented

@leehericks @woller

I just pushed a fix for this to the fix-no-matching-records-error branch (changes here: dc0a629).

Would you mind sourcing the gem from that branch and checking if it solves the issue?

I will do this as soon as I get back to work on Monday.

Foolish question but this would be changing my Gemfile to point to the github branch, right?

Thank you for your prompt work on this!

pilaf commented

@leehericks

this would be changing my Gemfile to point to the github branch, right?

Yeah, I think this should do the trick:

gem "fmrest", github: "beezwax/fmrest-ruby", branch: "fix-no-matching-records-error"

@pilaf
It works! Thank you for fixing this.

@pilaf
Works on all three situations, find_one => nil, find_some => [], count => 0

Thank you for fixing this! Looking forward to a gem version push.

pilaf commented

@woller @leehericks Thanks for reporting back! I just released v0.4.1 with this fix.