exception handling in new PHP client lib / mutateLink()

326 views
Skip to first unread message

Markus Baersch

unread,
Apr 20, 2017, 1:38:14 AM4/20/17
to AdWords API Forum

Hi,

switching from the old API version to v201702 I am currently struggling with the differences in exception handling. When I tried managedCustomerService->mutateLink with an already managed or invited cusomer id, the old version threw an exception and I could react to reasons like ALREADY_INVITED_BY_THIS_MANAGER / ALREADY_MANAGED_BY_THIS_MANAGER...  now the SOAP message shows up in the console. From what I read I guess that a custom LoggerInterface is the solution but unfortunately I am not familiar with PSR-3 and the code examples for ErrorHandling did not help in this case.  Using try / catch as before seems not to be a solution anymore.

Can anyone give me a hint how I can handle exceptions inside the code without logging errors to the console or a log file or even provide some sample code? 

Thanks
Markus

Ivan Bautista

unread,
Apr 20, 2017, 3:08:14 AM4/20/17
to AdWords API Forum
Hi Markus,

You may refer here for possible errors that will be thrown for ManagedCustomerService. You may build your exception handling logic based from the possible errors specified and just add or define a default or generic exception/error handling logic as a fallback. 

Regards,
Ivan
AdWords API Team

Markus Baersch

unread,
Apr 20, 2017, 4:42:45 AM4/20/17
to AdWords API Forum
Hi Ivan, 

thank you for the fast response... I found that page before, but unfortunately the exception does not occur - the function stops after calling mutateLink() with an already managed customer id; try-catch fails and the SOAP warning shows up directly inside the console. So the function gets terminated without returning any value or being able to handle the exception. 

[2017-04-20 10:37:48] AW_SOAP.WARNING: clientCustomerId=xxxxx operations=1 service=ManagedCustomerService method=mutateLink responseTime=346 requestId=00054d950e42c5210ac11e13d7077a46 server=adwords.google.com isFault=1 faultMessage=[ManagedCustomerServiceError.ALREADY_INVITED_BY_THIS_MANAGER @ operations[0]]


Here I have my ManagedCustomerServiceError.ALREADY_INVITED_BY_THIS_MANAGER... but how can I access and handle it? This does not work: 


    try {
      $result = $customerService->mutateLink($operations);
      $links = $result->getLinks() ;
      $link = $links[0];
      $newStatus = $link->getLinkStatus() ;
      if (strpos($newStatus, 'PENDING') >= 0) return "OK"; else return "ERR: ".$newStatus ;
    } catch (Exception $e) {
      //
      return "you will never see this line, sorry..." ; 
    }


best regards,
Markus

Ivan Bautista

unread,
Apr 20, 2017, 7:11:16 AM4/20/17
to AdWords API Forum
Hi Markus,

Apologies if I misunderstood your question earlier. I want to point out that those ManagedCustomerServiceErrors I mentioned earlier are ApiError objects in the AdWords API and not Exception objects in the context of PHP. Having said that, they should be handled the same way as how you handle other ApiError objects in the AdWords API. 

You may refer to this sample code for reference in handling ApiErrors and extracting ManagedCustomerServiceError information particularly the code section: try {...} catch (ApiException $apiException) {}. 

Markus Baersch

unread,
Apr 20, 2017, 7:57:32 AM4/20/17
to AdWords API Forum
Hi Ivan,

I tried that yesterday as well as I looked at the examples. But as I see now that attempt failed because I used Google\AdsApi\AdWords\v201702\cm\ManagedCustomerServiceError but forgot about Google\AdsApi\AdWords\v201702\cm\ApiException. Now I can finally access and handle the exception. 

One last question: Is there a way to suppress the SOAP warnings completely? They still show up in the console and so I adjusted adsapi_php.ini in order to log to a file instead. But I would prefer not to keep a logfile of already exceptions that are being handeled already. But anyway: the migrated function finally works - thank you for your help!  


best regards,
Markus

Ivan Bautista

unread,
Apr 20, 2017, 11:00:42 AM4/20/17
to AdWords API Forum
Hi Markus,

I'm glad that you were able to resolve your previous concern. 

With regards to filtering the SOAP warning logs, I suggest that you double check with the PHP client library team as we only handle concerns specific to the services and reports available in the AdWords API. You may also refer to the logging configurations specified in their Github guide for more relevant information.

Markus Baersch

unread,
Apr 20, 2017, 3:23:00 PM4/20/17
to AdWords API Forum
Hi Ivan,

thanks again - I will try my luck there to get rid of the messages.

best regards,
Markus

Reply all
Reply to author
Forward
0 new messages