Skip to content

Commit

Permalink
#37 better work with error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Jan 17, 2024
1 parent e4d1ffc commit d4bd5fe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/AbraFlexi/Banka.php
Expand Up @@ -45,9 +45,7 @@ class Banka extends RW implements \AbraFlexi\Document
*/
public function stahnoutVypisyOnline()
{
$this->pullMode = true;
$this->performRequest('nacteni-vypisu-online.json', 'PUT', 'txt');
$this->pullMode = false;
return ($this->lastResponseCode == 200);
}

Expand Down
3 changes: 2 additions & 1 deletion src/AbraFlexi/RO.php
Expand Up @@ -1228,10 +1228,11 @@ public function parseResponse($responseDecoded, $responseCode)
if (!empty($responseDecoded) && is_array($responseDecoded)) {
$this->parseError($responseDecoded);
}
$this->addStatusMessage($this->lastResponseCode . ': ' . $this->curlInfo['url'] . ' (' . $this->format . ') ' . json_encode($this->getErrors()), 'warning');
if ($this->throwException) {
$errors = $this->getErrors();
throw new Exception(empty($errors) ? 'Problem ' : $errors[0]['message'], $this);
} else {
$this->addStatusMessage($this->lastResponseCode . ': ' . $this->curlInfo['url'] . ' (' . $this->format . ') ' . json_encode($this->getErrors()), 'warning');
}
break;
}
Expand Down
5 changes: 2 additions & 3 deletions src/AbraFlexi/RW.php
Expand Up @@ -166,22 +166,21 @@ public function parseError(array $responseDecoded)

if (array_key_exists('errors', $result)) {
foreach ($result as $error) {
$this->errors[] = current($error);
$this->errors[] = is_array($error) ? current($error) : $error;
}
}
}
} else {
foreach ($responseDecoded['results'][0]['result'] as $result) {
if (array_key_exists('errors', $result)) {
foreach ($result as $error) {
$this->errors[] = current($error);
$this->errors[] = is_array($error) ? current($error) : $error;
}
}
}
}

foreach ($this->errors as $errorInfo) {
$this->addStatusMessage(array_key_exists('error', $errorInfo) ? $errorInfo['error'] : $errorInfo['message'], 'error');
if ($this->debug && array_key_exists('for', $errorInfo)) {
unset($errorInfo['message']);
$this->addStatusMessage(json_encode($errorInfo), 'debug');
Expand Down

0 comments on commit d4bd5fe

Please sign in to comment.