improve exception throwing with custom exception and use of code
This commit is contained in:
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])){
|
if(in_array($status_code,[200,201,204])){
|
||||||
return json_decode($result);
|
return json_decode($result);
|
||||||
}else{
|
}else{
|
||||||
throw new \Exception("API $status_code Code: ".$result);
|
throw new ApiException($result,$status_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user