Cleaning up exceptions in the Build controller

This commit is contained in:
Dan Cryer 2014-05-09 12:15:11 +01:00
parent fe813b057c
commit 7662202a39

View file

@ -10,6 +10,7 @@
namespace PHPCI\Controller;
use b8;
use b8\Exception\HttpException\NotFoundException;
use PHPCI\BuildFactory;
use PHPCI\Model\Build;
@ -36,7 +37,16 @@ class BuildController extends \PHPCI\Controller
*/
public function view($buildId)
{
$build = BuildFactory::getBuildById($buildId);
try {
$build = BuildFactory::getBuildById($buildId);
} catch (\Exception $ex) {
$build = null;
}
if (empty($build)) {
throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
}
$this->view->plugins = $this->getUiPlugins();
$this->view->build = $build;
$this->view->data = $this->getBuildData($build);
@ -110,6 +120,10 @@ class BuildController extends \PHPCI\Controller
{
$copy = BuildFactory::getBuildById($buildId);
if (empty($copy)) {
throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
}
$build = new Build();
$build->setProjectId($copy->getProjectId());
$build->setCommitId($copy->getCommitId());
@ -134,11 +148,10 @@ class BuildController extends \PHPCI\Controller
throw new \Exception('You do not have permission to do that.');
}
$build = BuildFactory::getBuildById($buildId);
$build = BuildFactory::getBuildById($buildId);
if (!$build) {
$this->response->setResponseCode(404);
return '404 - Not Found';
if (empty($build)) {
throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
}
$this->buildStore->delete($build);