Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using specific error classes #138

Open
ianks opened this issue Oct 12, 2017 · 1 comment
Open

Using specific error classes #138

ianks opened this issue Oct 12, 2017 · 1 comment

Comments

@ianks
Copy link
Contributor

ianks commented Oct 12, 2017

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
@mcloonan
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants