googleads / googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
Apache License 2.0
656 stars 769 forks source link

How to catch Exception and rerun Request #533

Closed gchicoye closed 6 years ago

gchicoye commented 6 years ago

Hi, I have from time to time issues with the LineItemCreativeAssociationService and updateLineItemCreativeAssociations Method, generating an uncaught exception.

PHP Fatal error: Uncaught exception 'Google\AdsApi\Dfp\v201802\ApiException' with message '[CommonError.CONCURRENT_MODIFICATION @ ]' in /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php:43

I would like my script to retry every 30 seconds 5 times this update, so I set up the calls this way

` $licaService = $this->dfpServices->get($this->session, LineItemCreativeAssociationService::class); $attempts = 0;

    do {
        try
        {
            $results = $licaService->updateLineItemCreativeAssociations($this->createLicaObject($licasToBeUpdated));
        } catch (Exception $e) {
            echo "\n\n======EXCEPTION======\n\n";
            var_dump($e);
            $attempts++;
            sleep(30);
            continue;
        }
        break;
    } while($attempts < 5);

`

However, it looks like I don't catch the exception...

How can I update my code to have it running smoothly?

Thanks!

Gabriel

thangduo commented 6 years ago

Could you please post the full stack trace?

gchicoye commented 6 years ago

@thangduo could you be more explicit? The full script is available here https://github.com/Insideall/dfp-prebid-lineitems

gchicoye commented 6 years ago

[2018-10-08 11:04:15] DFP_SOAP.WARNING: networkCode=157792674 service=LineItemCreativeAssociationService method=createLineItemCreativeAssociations responseTime=1308 requestId=278191f146dda59f4cf3f56c8070c37d server=ads.google.com isFault=1 faultMessage=[CommonError.CONCURRENT_MODIFICATION @ ]
[2018-10-08 11:04:15] DFP_SOAP.NOTICE: POST /apis/ads/publisher/v201802/LineItemCreativeAssociationService?wsdl HTTP/1.1 Host: ads.google.com Connection: close User-Agent: PHP-SOAP/5.6.38-0+deb8u1 Content-Type: text/xml; charset=utf-8 SOAPAction: "" Content-Length: 23901 Authorization: REDACTED

<?xml version="1.0" encoding="UTF-8"?>

157792674Insideall - Test 1 (DfpApi-PHP, googleads-php-lib/34.0.0, PHP/5.6.38-0+deb8u1)482004661313824634877672890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824634883372890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824634878272890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824631748772890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824631749072890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824634878872890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824631749372890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824631749972890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824631750572890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false482004661313824631751472890false1000200false1000250false1000300false100090false120600false160600false300100false3001000false300250false30050false300600false320100false32050false336280false970150false970250false97090false HTTP/1.1 500 Internal Server Error Content-Type: text/xml; charset=UTF-8 Date: Mon, 08 Oct 2018 09:04:15 GMT Expires: Mon, 08 Oct 2018 09:04:15 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35" Accept-Ranges: none Vary: Accept-Encoding Connection: close 278191f146dda59f4cf3f56c8070c37d1308soap:Server[CommonError.CONCURRENT_MODIFICATION @ ][CommonError.CONCURRENT_MODIFICATION @ ]CommonError.CONCURRENT_MODIFICATIONCONCURRENT_MODIFICATION PHP Fatal error: Uncaught exception 'Google\AdsApi\Dfp\v201802\ApiException' with message '[CommonError.CONCURRENT_MODIFICATION @ ]' in /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php:43 Stack trace: #0 /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php(43): ReflectionClass->newInstanceArgs(Array) #1 /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(203): Google\AdsApi\Common\Util\Reflection->createInstance('Google\\AdsApi\\D...', '[CommonError.CO...') #2 /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(164): Google\AdsApi\Common\AdsSoapClient->parseApiExceptionFromSoapFault(Object(SoapFault)) #3 /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/v201802/LineItemCreativeAssociationService.php(136): Google\AdsApi\Common\AdsSoapClient->__soapCall('createLineItemC...', Array) #4 /home/gabriel/dfp/app/Dfp/LineItemCreati in /home/gabriel/dfp/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php on line 43
gchicoye commented 6 years ago

Hi,

This was solved using use Google\AdsApi\Dfp\v201802\ApiException;

and

do { try { ... } catch (Api Exception $Exception) { ... }