Permalink
Browse files

exception handling, simplified highlighting

  • Loading branch information...
1 parent 574ff7e commit 9e50acfbdf069e93f72fa53ad1d6a6c47c404ad1 @l3pp4rd committed Jan 19, 2012
@@ -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>
@@ -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
{
@@ -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');
}
@@ -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];
@@ -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');
}
/**
@@ -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.

Oops, something went wrong.
@@ -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
{
@@ -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
));
View
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.