Skip to content

Commit

Permalink
exception handling, simplified highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
l3pp4rd committed Jan 19, 2012
1 parent 574ff7e commit 9e50acf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/Resources/TwigBundle/views/Exception/error404.html.twig
Expand Up @@ -7,5 +7,8 @@
<body>
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
<div class="row" style="text-align:center;">
<img alt="404 error" src="{{ asset('img/404camionette.jpg') }}">
</div>
</body>
</html>
19 changes: 14 additions & 5 deletions src/Gedmo/BlogBundle/Controller/ArticleController.php
Expand Up @@ -11,6 +11,8 @@
use Gedmo\BlogBundle\Entity\Article;
use Gedmo\BlogBundle\Entity\Comment;
use Gedmo\BlogBundle\Entity\EmailMessage;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;

class ArticleController extends Controller
{
Expand All @@ -31,11 +33,14 @@ public function indexAction()
____SQL;
$q = $em->createQuery($dql);

$whitelist = array('a.created');
$distinct = false;
$paginator = $this->get('knp_paginator');
$articles = $paginator->paginate(
$q,
$this->get('request')->query->get('page', 1),
20
20,
compact('whitelist', 'distinct')
);
return compact('articles');
}
Expand All @@ -60,10 +65,14 @@ public function viewAction($slug)
$q = $em->createQuery($dql);
$q->setMaxResults(1);
$q->setParameters(compact('slug'));
$article = $q->getSingleResult();
$article = $q->getResult();
if (!$article) {
throw new \RuntimeException("Article was not found by {$slug}");
throw new NotFoundHttpException(sprintf(
'Failed to find Article by slug:[%s]',
$slug
));
}
$article = current($article);
$countComments = intval($article['num_comments']);
$article = $article[0];

Expand Down Expand Up @@ -114,7 +123,7 @@ public function addAction()
$params['created'] = $this->get('time.templating.helper.time')->diff(new \DateTime());
return new Response(json_encode($params));
}
throw new \BadFunctionCallException('Invalid call context');
throw new MethodNotAllowedHttpException('Invalid call context');
}

/**
Expand Down Expand Up @@ -145,6 +154,6 @@ public function commentsAction(Article $article, $offset)
}, $q->getArrayResult());
return new Response(json_encode($comments));
}
throw new \BadFunctionCallException('Invalid call context');
throw new MethodNotAllowedHttpException('Invalid call context');
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Gedmo/DemoBundle/Controller/CategoryController.php
Expand Up @@ -9,6 +9,7 @@
use Gedmo\DemoBundle\Form\CategoryType;
use Gedmo\Translatable\TranslationListener;
use Doctrine\ORM\Query;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class CategoryController extends Controller
{
Expand Down Expand Up @@ -273,7 +274,7 @@ private function findNodeOr404($id)
$this->setTranslatableHints($q);
$node = $q->getResult();
if (!$node) {
throw $this->createNotFoundException(sprintf(
throw new NotFoundHttpException(sprintf(
'Failed to find Category by id:[%s]',
$id
));
Expand Down
Binary file added web/img/404camionette.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9e50acf

Please sign in to comment.