From df9a661bb44129ced371eda2efc14cd1f5fec31d Mon Sep 17 00:00:00 2001 From: Manuel Thomsen Date: Thu, 28 Sep 2017 15:42:14 +0200 Subject: [PATCH] Handle failed requests that do not contain errors Some responses from e-conomic do not return `errors`. For instance, 404 errors return a response that looks like this: ``` "message": "Resource not found.", "developerHint": "The API tries to provide all the resource urls you need. If you have hard coded urls yourself, then try to look at the enclosing collection for hypermedia information on where the resource you are looking for could be.", "logId": "377aeee92480bbc72a28eaeb2cc1dbe0", "httpStatusCode": 404, "logTime": "2017-09-28T15:37:32", ``` This simple change checks if `$formattedResponse->errors` is set, and only updates `$this->errors` when that's the case. --- src/Economic.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Economic.php b/src/Economic.php index 5ba41d2..8534ec1 100644 --- a/src/Economic.php +++ b/src/Economic.php @@ -358,10 +358,13 @@ private function isSuccessful($response, $formattedResponse, $timeout) if (isset($formattedResponse->message)) { $this->lastError = sprintf('%d: %s', $formattedResponse->httpStatusCode, $formattedResponse->message); - $this->errors = $formattedResponse->errors; + + if (isset($formattedResponse->errors)) { + $this->errors = $formattedResponse->errors; + } return false; } return false; } -} \ No newline at end of file +}