Skip to content

Commit

Permalink
moved error into the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Jun 1, 2013
1 parent be541e3 commit e26ae25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 11 additions & 5 deletions src/PUGX/BadgeBundle/Controller/BadgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

class BadgeController extends ContainerAware
{
CONST ERROR_TEXT_GENERIC = 'ERR 1 ';
CONST ERROR_TEXT_NOT_A_NUMBER = 'ERR 2 ';
CONST ERROR_TEXT_CLIENT_EXCEPTION = 'ERR 3 ';

/**
* @Route("/{repository}/downloads.png",
* name = "pugx_badge",
Expand Down Expand Up @@ -53,9 +57,9 @@ public function downloadsAction($repository, $type = 'total')
$text = $this->container->get('package_manager')->getPackageDownloads($package, $type);
$status = 200;
} catch (UnexpectedValueException $e) {
$text = ImageCreator::ERROR_TEXT_GENERIC;
$text = self::ERROR_TEXT_CLIENT_EXCEPTION;
} catch (\Exception $e){
$text = ImageCreator::ERROR_TEXT_CLIENT_EXCEPTION;
$text = self::ERROR_TEXT_GENERIC;
}

$image = $imageCreator->createDownloadsImage($text);
Expand Down Expand Up @@ -87,7 +91,7 @@ public function versionAction($repository, $latest = 'stable')
{
$image = null;
$outputFilename = sprintf('%s.png', $latest);
$error = 'Err';
$error = self::ERROR_TEXT_GENERIC;
$status = 500;

try {
Expand All @@ -101,8 +105,10 @@ public function versionAction($repository, $latest = 'stable')
}

$status = 200;
} catch (\Exception $e) {
$error = 'Err 01';
} catch (UnexpectedValueException $e) {
$error = self::ERROR_TEXT_CLIENT_EXCEPTION;
} catch (\Exception $e){
$error = self::ERROR_TEXT_GENERIC;
}

if (null == $image) {
Expand Down
4 changes: 0 additions & 4 deletions src/PUGX/BadgeBundle/Service/ImageCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

class ImageCreator implements ImageCreatorInterface
{
CONST ERROR_TEXT_GENERIC = 'ERR 1 ';
CONST ERROR_TEXT_NOT_A_NUMBER = 'ERR 2 ';
CONST ERROR_TEXT_CLIENT_EXCEPTION = 'ERR 3 ';

private $logger;
protected $dispatcher;
protected $imageNames = array('empty' => 'empty.png', 'downloads' => 'downloads.png', 'stable' => 'stable.png', 'unstable' => 'unstable.png');
Expand Down
4 changes: 2 additions & 2 deletions src/PUGX/BadgeBundle/Service/PackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function instantiatePackage()
}

/**
* Create a new Package decorated from the Api Package.
* Create a new Package decorated with the Api Package.
*
* @param ApiPackage $apiPackage
*
Expand All @@ -56,7 +56,7 @@ public function instantiateAndDecoratePackage(ApiPackage $apiPackage)
}

/**
* Returns package if found.
* Returns package if founded.
*
* @param string $repository
*
Expand Down

0 comments on commit e26ae25

Please sign in to comment.