Mangopay / mangopay2-ruby-sdk

Ruby Gem for MANGOPAY
https://rubygems.org/gems/mangopay
MIT License
42 stars 38 forks source link

check if object exists #55

Closed Sashkan closed 8 years ago

Sashkan commented 8 years ago

I'm using a simple rake task to browse through my transactions. Each of my payments has its own mangopay_user_id. Is there a way to test the ID without raising an error if the object does not exist ?

  @payin = MangoPay::PayIn.fetch(payment.mangopay_charge_id)

raises me a:

The ressource does not exist RessourceNotFound: Cannot found the ressource PayIn with the id=52282550

And therefore aborst the rake.

javiercr commented 8 years ago

@Sashkan you can just use ruby's rescue to handle that case.

begin
  @payin = MangoPay::PayIn.fetch(payment.mangopay_charge_id)
rescue MangoPay::ResponseError => error
  puts error
end