55use Exception ;
66use GuzzleHttp \Client ;
77use PHPCensor \Controller ;
8+ use PHPCensor \Exception \HttpException \ForbiddenException ;
89use PHPCensor \Exception \HttpException \NotFoundException ;
910use PHPCensor \Exception \InvalidArgumentException ;
11+ use PHPCensor \Exception \RuntimeException ;
1012use PHPCensor \Helper \Lang ;
1113use PHPCensor \Http \Response ;
1214use PHPCensor \Model \Build ;
@@ -292,24 +294,24 @@ protected function createBuild(
292294 protected function fetchProject ($ projectId , array $ expectedType )
293295 {
294296 if (empty ($ projectId )) {
295- throw new Exception ('Project does not exist: ' . $ projectId );
297+ throw new NotFoundException ('Project does not exist: ' . $ projectId );
296298 }
297299
298300 if (is_numeric ($ projectId )) {
299301 $ project = $ this ->projectStore ->getById ((int )$ projectId );
300302 } else {
301303 $ projects = $ this ->projectStore ->getByTitle ($ projectId , 2 );
302304 if ($ projects ['count ' ] < 1 ) {
303- throw new Exception ('Project does not found: ' . $ projectId );
305+ throw new NotFoundException ('Project does not found: ' . $ projectId );
304306 }
305307 if ($ projects ['count ' ] > 1 ) {
306- throw new Exception ('Project id is ambiguous: ' . $ projectId );
308+ throw new NotFoundException ('Project id is ambiguous: ' . $ projectId );
307309 }
308310 $ project = reset ($ projects ['items ' ]);
309311 }
310312
311313 if (!in_array ($ project ->getType (), $ expectedType , true )) {
312- throw new Exception ('Wrong project type: ' . $ project ->getType ());
314+ throw new NotFoundException ('Wrong project type: ' . $ project ->getType ());
313315 }
314316
315317 return $ project ;
@@ -529,7 +531,7 @@ protected function bitbucketPullRequest(Project $project, array $payload)
529531 $ appPassword = $ this ->configuration ->get ('php-censor.bitbucket.app_password ' );
530532
531533 if (empty ($ username ) || empty ($ appPassword )) {
532- throw new Exception ('Please provide Username and App Password of your Bitbucket account. ' );
534+ throw new ForbiddenException ('Please provide Username and App Password of your Bitbucket account. ' );
533535 }
534536
535537 $ commitsUrl = $ payload ['pullrequest ' ]['links ' ]['commits ' ]['href ' ];
@@ -542,7 +544,7 @@ protected function bitbucketPullRequest(Project $project, array $payload)
542544
543545 // Check we got a success response:
544546 if ($ httpStatus < 200 || $ httpStatus >= 300 ) {
545- throw new Exception ('Could not get commits, failed API request. ' );
547+ throw new RuntimeException ('Could not get commits, failed API request. ' );
546548 }
547549
548550 $ results = [];
@@ -833,7 +835,7 @@ protected function githubPullRequest(Project $project, array $payload)
833835
834836 // Check we got a success response:
835837 if ($ status < 200 || $ status >= 300 ) {
836- throw new Exception ('Could not get commits, failed API request. ' );
838+ throw new RuntimeException ('Could not get commits, failed API request. ' );
837839 }
838840
839841 $ results = [];
0 commit comments