| 1 |
<?php |
| 2 |
/** |
| 3 |
* Extension of WP_Error for WP Offload SES. |
| 4 |
* |
| 5 |
* @author Delicious Brains |
| 6 |
* @package WP Offload SES |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace DeliciousBrains\WP_Offload_SES; |
| 10 |
|
| 11 |
/** |
| 12 |
* Class Error |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class Error extends \WP_Error { |
| 17 |
|
| 18 |
// Generic errors. |
| 19 |
public static $mail_function_exists = 101; |
| 20 |
public static $missing_access_keys = 102; |
| 21 |
|
| 22 |
// API related errors. |
| 23 |
public static $api_get_quota = 201; |
| 24 |
public static $api_send = 202; |
| 25 |
public static $api_get_identities = 203; |
| 26 |
public static $api_verify_domain = 204; |
| 27 |
public static $api_verify_email = 205; |
| 28 |
public static $api_delete_identity = 206; |
| 29 |
public static $api_get_identity_verification_attributes = 207; |
| 30 |
|
| 31 |
// License related errors. |
| 32 |
public static $licence_error = 301; |
| 33 |
|
| 34 |
// Cron related error. |
| 35 |
public static $send_cron_email = 401; |
| 36 |
|
| 37 |
/** |
| 38 |
* Error constructor. |
| 39 |
* |
| 40 |
* @param string|int $code $error Error code. |
| 41 |
* @param string|\WP_Error $error Error message or instance of WP_Error. |
| 42 |
* @param mixed $data Optional. Error data. |
| 43 |
*/ |
| 44 |
public function __construct( $code = '', $error = '', $data = '' ) { |
| 45 |
if ( is_wp_error( $error ) ) { |
| 46 |
$message = $error->get_error_code() . ': ' . $error->get_error_message(); |
| 47 |
$data = ( $data ) ? $data : $error->get_error_data(); |
| 48 |
} else { |
| 49 |
$message = $error; |
| 50 |
} |
| 51 |
|
| 52 |
// Debug log. |
| 53 |
$this->log_error( $code, $message, $data ); |
| 54 |
|
| 55 |
parent::__construct( $code, $message, $data ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Log error |
| 60 |
* |
| 61 |
* @param string $code The error code to log. |
| 62 |
* @param string $message The message to log. |
| 63 |
* @param string|array $data Any relevant data for the error. |
| 64 |
*/ |
| 65 |
private function log_error( $code, $message, $data ) { |
| 66 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 67 |
|
| 68 |
if ( ! empty( $data ) && is_string( $data ) ) { |
| 69 |
$message .= ' (' . $data . ')'; |
| 70 |
} |
| 71 |
|
| 72 |
error_log( 'WP Offload SES #' . $code . ': ' . $message ); // phpcs:ignore |
| 73 |
|
| 74 |
if ( is_array( $data ) || is_object( $data ) ) { |
| 75 |
error_log( print_r( $data, true ) ); // phpcs:ignore |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
|