analytics-admin
2 years ago
class-ga-lib-api-client-exception.php
4 years ago
class-ga-lib-api-client.php
4 years ago
class-ga-lib-api-request-exception.php
4 years ago
class-ga-lib-api-request.php
4 years ago
class-ga-lib-api-response.php
4 years ago
class-ga-lib-google-api-client-accountsummaries-exception.php
4 years ago
class-ga-lib-google-api-client-authcode-exception.php
4 years ago
class-ga-lib-google-api-client-data-exception.php
4 years ago
class-ga-lib-google-api-client-exception.php
4 years ago
class-ga-lib-google-api-client-refreshtoken-exception.php
4 years ago
class-ga-lib-google-api-client.php
3 years ago
class-ga-lib-sharethis-api-client-alerts-exception.php
4 years ago
class-ga-lib-sharethis-api-client-exception.php
4 years ago
class-ga-lib-sharethis-api-client-invaliddomain-exception.php
4 years ago
class-ga-lib-sharethis-api-client-invite-exception.php
4 years ago
class-ga-lib-sharethis-api-client-verify-exception.php
4 years ago
class-ga-lib-sharethis-api-client.php
4 years ago
class-ga-lib-google-api-client-exception.php
91 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Google API client exception. |
| 4 | * |
| 5 | * @package GoogleAnalytics |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Google API client exception. |
| 10 | */ |
| 11 | class Ga_Lib_Google_Api_Client_Exception extends Ga_Lib_Api_Client_Exception { |
| 12 | /** |
| 13 | * Google error response. |
| 14 | * |
| 15 | * @var string|null |
| 16 | */ |
| 17 | private $google_error_response = null; |
| 18 | |
| 19 | /** |
| 20 | * Constructor. |
| 21 | * |
| 22 | * @param string $msg Exception message. |
| 23 | */ |
| 24 | public function __construct( $msg ) { |
| 25 | $this->set_google_error_response( $msg ); |
| 26 | $data = $this->get_error_response_data( $msg ); |
| 27 | parent::__construct( $data['error']['message'], $data['error']['code'] ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Sets google JSON response. |
| 32 | * Response structure: |
| 33 | * { |
| 34 | * "error": { |
| 35 | * "code": 403, |
| 36 | * "message": "User does not have sufficient permissions for this profile.", |
| 37 | * "status": "PERMISSION_DENIED", |
| 38 | * "details": [ |
| 39 | * { |
| 40 | * "@type": "type.googleapis.com/google.rpc.DebugInfo", |
| 41 | * "detail": "[ORIGINAL ERROR] generic::permission_denied: User does not have sufficient permissions for this profile. |
| 42 | * [google.rpc.error_details_ext] { message: \"User does not have sufficient permissions for this profile.\" }" |
| 43 | * } |
| 44 | * ] |
| 45 | * } |
| 46 | * } |
| 47 | * |
| 48 | * @param string $response Response string. |
| 49 | */ |
| 50 | public function set_google_error_response( $response ) { |
| 51 | $this->google_error_response = $response; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get Google error response. |
| 56 | * |
| 57 | * @return string |
| 58 | */ |
| 59 | public function get_google_error_response() { |
| 60 | return $this->google_error_response; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Decodes JSON response |
| 65 | * |
| 66 | * @param string $response Response string. |
| 67 | * |
| 68 | * @return array Decoded object array. |
| 69 | */ |
| 70 | protected function get_error_response_data( $response ) { |
| 71 | $data = json_decode( $response, true ); |
| 72 | if ( is_array( $data['error'] ) && ! empty( $data['error'] ) && ! empty( $data['error']['message'] ) && ! empty( $data['error']['code'] ) ) { |
| 73 | return $data; |
| 74 | } elseif ( ! empty( $data['error'] ) ) { |
| 75 | return array( |
| 76 | 'error' => array( |
| 77 | 'message' => $data['error'], |
| 78 | 'code' => 500, |
| 79 | ), |
| 80 | ); |
| 81 | } else { |
| 82 | return array( |
| 83 | 'error' => array( |
| 84 | 'message' => __( 'Google Reporting API - unknown error.' ), |
| 85 | 'code' => 500, |
| 86 | ), |
| 87 | ); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 |