Skip to content

Commit 2c0e6ca

Browse files
authored
handle importXmlInternalError gracefully in RO.php
parseResponse() was throwing "Cannot access offset of type string on string" from line 1301 when response from FlexiBee came with following data: ``` ["@Version" => "1.0", "success" => "false", "stats" => ["created" => "0", "updated" => "1", "deleted" => "0", "skipped" => "0", "failed" => "0"], "results" => [["errors" => [["message" => "Interní chyba aplikace.", "messageCode" => "importXmlInternalError"]]]]] ``` That made it hard to diagnose problems, because it stripped out relevant information from FlexiBee response. This commit adds fallback for this case when message is not found where expected.
1 parent e183c45 commit 2c0e6ca

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/AbraFlexi/RO.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,14 @@ public function parseResponse($responseDecoded, $responseCode)
12981298

12991299
// no break
13001300
case 401:
1301-
$msg = (\array_key_exists('message', $responseDecoded) ? $responseDecoded['message'] : $responseDecoded[key($responseDecoded)]['message']).' for '.$this->getApiURL();
1301+
if (\array_key_exists('message', $responseDecoded)) {
1302+
$msg = $responseDecoded['message'];
1303+
} elseif (isset($responseDecoded[key($responseDecoded)]['message'])) {
1304+
$msg = $responseDecoded[key($responseDecoded)]['message'];
1305+
} else {
1306+
$msg = sprintf("Unexpected response data [%s]: %s", $responseCode, json_encode($responseDecoded));
1307+
}
1308+
$msg .= ' for '.$this->getApiURL();
13021309
$this->addStatusMessage($msg, 'error');
13031310

13041311
if ($this->throwException) {

0 commit comments

Comments
 (0)