diff --git a/src/DeepL.php b/src/DeepL.php index 0f74664..16bc252 100644 --- a/src/DeepL.php +++ b/src/DeepL.php @@ -431,12 +431,12 @@ protected function request($url, $body) $httpCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE); $responseArray = json_decode($response, true); - if ($httpCode != 200) { + if ($httpCode != 200 && is_array($responseArray) && array_key_exists('message', $responseArray)) { throw new DeepLException($responseArray['message'], $httpCode); } if (false === is_array($responseArray)) { - throw new DeepLException('The Response seems to not be valid JSON.'); + throw new DeepLException('The Response seems to not be valid JSON.', $httpCode); } return $responseArray;