Commit 3c36c34a authored by Donal McMullan's avatar Donal McMullan
Browse files

Handle error responses from remote server more elegantly

parent 7dd3ad6e
......@@ -83,6 +83,18 @@ function get_public_key($uri, $application=null) {
if (empty($raw)) {
throw new XmlrpcClientException('CURL connection failed');
}
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response_code_prefix = substr($response_code, 0, 1);
if ('2' != $response_code_prefix) {
if ('4' == $response_code_prefix) {
throw new XmlrpcClientException('Client error code: ', $response_code);
} elseif('5' == $response_code_prefix) {
throw new XmlrpcClientException('An error occurred at the remote server. Code: ', $response_code);
}
}
$res = xmlrpc_decode($raw);
curl_close($ch);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment