mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-29 16:36:07 +03:00
Shows response message on 400, 401 and 404 errors
Adds the actual response message to the errors thrown on 400, 401 and 404 response codes. This provides a lot more useful info than the current messages. The message doesn’t really give you much to go one. I spent hours trying to find what I did wrong, double checking my API keys and looking up the error on google.
This commit is contained in:
parent
fbe34ce59a
commit
e1406e3936
@ -184,13 +184,13 @@ class RestClient {
|
||||
$result->http_response_body = $data && $jsonResponseData === null ? $data : $jsonResponseData;
|
||||
}
|
||||
elseif($httpResponseCode == 400){
|
||||
throw new MissingRequiredParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_PARAMETERS);
|
||||
throw new MissingRequiredParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_PARAMETERS . $this->getResponseExceptionMessage($responseObj));
|
||||
}
|
||||
elseif($httpResponseCode == 401){
|
||||
throw new InvalidCredentials(ExceptionMessages::EXCEPTION_INVALID_CREDENTIALS);
|
||||
}
|
||||
elseif($httpResponseCode == 404){
|
||||
throw new MissingEndpoint(ExceptionMessages::EXCEPTION_MISSING_ENDPOINT);
|
||||
throw new MissingEndpoint(ExceptionMessages::EXCEPTION_MISSING_ENDPOINT . $this->getResponseExceptionMessage($responseObj));
|
||||
}
|
||||
else{
|
||||
throw new GenericHTTPError(ExceptionMessages::EXCEPTION_GENERIC_HTTP_ERROR, $httpResponseCode, $responseObj->getBody());
|
||||
@ -199,6 +199,18 @@ class RestClient {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Guzzle\Http\Message\Response $responseObj
|
||||
* @return string
|
||||
*/
|
||||
protected function getResponseExceptionMessage(\Guzzle\Http\Message\Response $responseObj){
|
||||
$body = (string)$responseObj->getBody();
|
||||
$response = json_decode($body);
|
||||
if (json_last_error() == JSON_ERROR_NONE && isset($response->message)) {
|
||||
return " " . $response->message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $apiEndpoint
|
||||
* @param string $apiVersion
|
||||
|
Loading…
Reference in New Issue
Block a user