Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Merge branch 'feature/improve-errors'
Browse files Browse the repository at this point in the history
  • Loading branch information
roelvanduijnhoven committed Jan 29, 2021
2 parents 18bbad5 + cf6ca5a commit 7fbb4b8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/OP/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ protected function _parseReply ($str = '')

$arr = OP_API::convertXmlToPhpObj($dom->documentElement);

if (!is_array($arr) || !array_key_exists('reply', $arr)) {
if (!is_array($arr)) {
throw new OP_API_Exception(sprintf("Could not interpret response: %s", (string)$arr));
}

if (isset($arr['reply']['code']) && $arr['reply']['code'] == 4005) {
throw new OP_API_Exception("API is temporarily unavailable due to maintenance", 4005);
}

if (!array_key_exists('code', $arr['reply']) || !array_key_exists('desc', $arr['reply']) || !array_key_exists('data', $arr['reply'])) {
if (!array_key_exists('reply', $arr)
|| !array_key_exists('code', $arr['reply'])
|| !array_key_exists('desc', $arr['reply'])
|| !array_key_exists('data', $arr['reply'])
) {
throw new OP_API_Exception(sprintf("Could not interpret response, missing mandatory fields. Response: %s", print_r($arr, true)));
}

Expand Down

0 comments on commit 7fbb4b8

Please sign in to comment.