Move decode error method, minor text update for error strings

the method "decodeExceptionMessage" has moved from
AmazonIncentives\AmazonIncentives to
AmazonIncentives\Exceptions\AmazonErrors

The old method is currently tagged deprecated internal via @deprecated
PHPdoc entry
This commit is contained in:
2022-06-13 18:06:16 +09:00
parent fd5477269b
commit 05b33ac157
3 changed files with 32 additions and 17 deletions

View File

@@ -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;
} }
// ********************************************************************* // *********************************************************************

View File

@@ -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__