improve exception throwing with custom exception and use of code
This commit is contained in:
parent
83eea50cf9
commit
907c686bad
10
src/ApiException.php
Normal file
10
src/ApiException.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace JHodges\GiteaBot;
|
||||
|
||||
class ApiException extends \Exception{
|
||||
|
||||
public function __toString() {
|
||||
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
|
||||
}
|
||||
|
||||
}
|
@ -54,7 +54,7 @@ class Client{
|
||||
if(in_array($status_code,[200,201,204])){
|
||||
return json_decode($result);
|
||||
}else{
|
||||
throw new \Exception("API $status_code Code: ".$result);
|
||||
throw new ApiException($result,$status_code);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user