Skip to content

Commit

Permalink
Move GoogleAdsFailures::init to the error_handler middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemd24 committed Sep 18, 2023
1 parent 2e21e0d commit 9546add
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Internal/DependencyManagement/GoogleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Http\Message\RequestInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Http\Message\ResponseInterface;
use Google\Ads\GoogleAds\Util\V14\GoogleAdsFailures;
use Jetpack_Options;

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -192,6 +193,14 @@ protected function error_handler(): callable {
return $handler( $request, $options )->then(
function ( ResponseInterface $response ) use ( $request ) {
$code = $response->getStatusCode();

$path = $request->getUri()->getPath();

// Partial Failures come back with a status code of 200, so it's necessary to call GoogleAdsFailures:init every time..
if ( strpos( $path, 'google-ads' ) !== false ) {
GoogleAdsFailures::init();
}

if ( $code < 400 ) {
return $response;
}
Expand Down

0 comments on commit 9546add

Please sign in to comment.