Move decodeExceptionMessage to Exceptions class
The method "decodeExceptionMessage" previous located in the AmazonIncentives\AmazonIncentives main class has been moved to the AmazonIncentives\Exceptions\AmazonErrors where it logically belongs. A deprecation phpdoc message has been added for the current version. Update error messages in curl error part and remove double spaces.
This commit is contained in:
@@ -137,22 +137,12 @@ final class AmazonIncentives
|
|||||||
*
|
*
|
||||||
* @param string $message Exception message json string
|
* @param string $message Exception message json string
|
||||||
* @return array<mixed> Decoded with code, type, message fields
|
* @return array<mixed> Decoded with code, type, message fields
|
||||||
|
*
|
||||||
|
* @deprecated use \gullevek\AmazonIncentives\Exceptions\AmazonErrors::decodeExceptionMessage()
|
||||||
*/
|
*/
|
||||||
public static function decodeExceptionMessage(string $message): array
|
public static function decodeExceptionMessage(string $message): array
|
||||||
{
|
{
|
||||||
$message_ar = json_decode($message, true);
|
return AmazonErrors::decodeExceptionMessage($message);
|
||||||
// if we have an error, build empty block and only fill message
|
|
||||||
if (json_last_error()) {
|
|
||||||
$message_ar = [
|
|
||||||
'status' => '',
|
|
||||||
'code' => '',
|
|
||||||
'type' => '',
|
|
||||||
'message' => $message,
|
|
||||||
'log_id' => '',
|
|
||||||
'log' => []
|
|
||||||
];
|
|
||||||
}
|
|
||||||
return $message_ar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
|
|||||||
@@ -91,13 +91,13 @@ class Client implements ClientInterface
|
|||||||
case CURLE_COULDNT_CONNECT:
|
case CURLE_COULDNT_CONNECT:
|
||||||
case CURLE_COULDNT_RESOLVE_HOST:
|
case CURLE_COULDNT_RESOLVE_HOST:
|
||||||
case CURLE_OPERATION_TIMEOUTED:
|
case CURLE_OPERATION_TIMEOUTED:
|
||||||
$message = 'Could not connect to AWS (' . $url . '). Please check your '
|
$message = 'Could not connect to AWS (' . $url . '). Please check your '
|
||||||
. 'internet connection and try again. [' . $message . ']';
|
. 'internet connection and try again. [' . $message . ']';
|
||||||
break;
|
break;
|
||||||
case CURLE_SSL_PEER_CERTIFICATE:
|
case CURLE_SSL_PEER_CERTIFICATE:
|
||||||
$message = 'Could not verify AWS SSL certificate. Please make sure '
|
$message = 'Could not verify AWS SSL certificate. Please make sure '
|
||||||
. 'that your network is not intercepting certificates. '
|
. 'that your network is not intercepting certificates. '
|
||||||
. '(Try going to ' . $url . 'in your browser.) '
|
. '(Try going to ' . $url . 'in your browser.) '
|
||||||
. '[' . $message . ']';
|
. '[' . $message . ']';
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
@@ -39,6 +39,31 @@ final class AmazonErrors extends RuntimeException
|
|||||||
$_error_code
|
$_error_code
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the Exception message body
|
||||||
|
* Returns an array with code (Amazon error codes), type (Amazon error info)
|
||||||
|
* message (Amazon returned error message string)
|
||||||
|
*
|
||||||
|
* @param string $message Exception message json string
|
||||||
|
* @return array<mixed> Decoded with code, type, message fields
|
||||||
|
*/
|
||||||
|
public static function decodeExceptionMessage(string $message): array
|
||||||
|
{
|
||||||
|
$message_ar = json_decode($message, true);
|
||||||
|
// if we have an error, build empty block and only fill message
|
||||||
|
if (json_last_error()) {
|
||||||
|
$message_ar = [
|
||||||
|
'status' => '',
|
||||||
|
'code' => '',
|
||||||
|
'type' => '',
|
||||||
|
'message' => $message,
|
||||||
|
'log_id' => '',
|
||||||
|
'log' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $message_ar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
Reference in New Issue
Block a user