google-api-ads-ruby
google-api-ads-ruby copied to clipboard
Using specific error classes
It would be nice if this library supported exeception classes for the types of exceptions that could be received. Right now, in order to catch a specific error, I end up doing something like this
def invite_customer_to_mcc(customer)
mcc_service.mutate_link(link_operations(customer))
rescue AdwordsApi::Errors::ApiException => e
filter_permissable_errors(e, customer: customer)
end
def filter_permissable_errors(e, customer:)
permissible_reasons = %w[ALREADY_MANAGED_BY_THIS_MANAGER
ALREADY_INVITED_BY_THIS_MANAGER
TOO_MANY_INVITES]
impermissible_errors = e.errors.reject do |err|
permissible_reasons.include?(err[:reason])
end
throw e unless impermissible_errors.empty?
log_permissible_errors(customer, e)
true
end
It would be nice to just (or something similiar):
def invite_customer_to_mcc(customer)
tries = 2
begin
mcc_service.mutate_link(link_operations(customer))
rescue AdwordsApi::Errors::AlreadyManagedByThisCustomer => e
filter_permissable_errors(e, customer: customer)
end
end
Thanks for the suggestion! I do agree that this would be an improved workflow for dealing with errors, but I don't think we're going to have the resources to work on it soon. I'll talk to the rest of my team to see if we are going to be able to prioritize it.