Skip to content

Commit

Permalink
Fix exception catch logic. (#27)
Browse files Browse the repository at this point in the history
catch節が普通のExceptionで失敗していたので、GuzzleExceptionの場合に処理を分ける
  • Loading branch information
fumikito committed May 30, 2023
2 parents 798cd80 + 805fcbd commit c5705c1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Kunoichi/GaCommunicator/Services/Ga4Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Kunoichi\GaCommunicator\Services;

use GuzzleHttp\Exception\GuzzleException;

/**
* Abstract layer for GA4.
*/
Expand Down Expand Up @@ -57,10 +59,14 @@ public function ga4_get_report( $request, $callback = null ) {
}
$results = empty( $result['rows'] ) ? [] : $result['rows'];
return array_map( $callback, $results );
} catch ( \Exception $e ) {
} catch ( GuzzleException $e ) {
return new \WP_Error( 'ga_communicator_api_error', $e->getResponse()->getBody()->getContents(), [
'response' => $e->getCode(),
] );
} catch ( \Exception $e ) {
return new \WP_Error( 'ga_communicator_api_error', $e->getMessage(), [
'response' => $e->getCode(),
] );
}
}

Expand Down Expand Up @@ -120,10 +126,14 @@ public function ga4_realtime_report( $request = [] ) {
$response[] = $parsed;
}
return $response;
} catch ( \Exception $e ) {
} catch ( GuzzleException $e ) {
return new \WP_Error( 'ga_communicator_api_error', $e->getResponse()->getBody()->getContents(), [
'response' => $e->getCode(),
] );
} catch ( \Exception $e ) {
return new \WP_Error( 'ga_communicator_api_error', $e->getMessage(), [
'response' => $e->getCode(),
] );
}
}

Expand Down

0 comments on commit c5705c1

Please sign in to comment.