improve exception throwing with custom exception and use of code

This commit is contained in:
James 2021-01-01 12:14:29 +00:00
parent 83eea50cf9
commit 907c686bad
2 changed files with 11 additions and 1 deletions

10
src/ApiException.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace JHodges\GiteaBot;
class ApiException extends \Exception{
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
}

View File

@ -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);
}
}