Skip to content

Using specific error classes #138

@ianks

Description

@ianks

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions