throw exception on API error
This commit is contained in:
parent
ba76fded92
commit
1ee076aac6
@ -42,9 +42,14 @@ class Client{
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);
|
||||
}
|
||||
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$result = curl_exec($ch);
|
||||
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
return json_decode($result);
|
||||
|
||||
if(in_array($status_code,[200,201])){
|
||||
return json_decode($result);
|
||||
}else{
|
||||
throw new Exception("API $status_code Code: ".$result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user