Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7c658b

Browse files
committed
Use simpler example
1 parent 41f99d5 commit e7c658b

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

cookbook/controller/error_pages.rst

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -229,31 +229,25 @@ example, we gonna override the showAction method::
229229
230230
namespace AppBundle\Controller;
231231

232+
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController;
232233
use Symfony\Component\HttpFoundation\Request;
233234
use Symfony\Component\HttpKernel\Exception\FlattenException;
234235
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
235-
use Symfony\Component\HttpFoundation\Response;
236-
237-
class ExceptionController extends \Symfony\Bundle\TwigBundle\Controller\ExceptionController
236+
use Symfony\Component\HttpFoundation\JsonResponse;
237+
238+
class ExceptionController extends BaseExceptionController
238239
{
240+
/**
241+
* {@inheritdoc}
242+
*/
239243
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
240244
{
241-
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
242-
$showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC
243-
244-
// $code = $exception->getStatusCode();
245-
$code = 500; // Route exceptions will throw status code 500
246-
247-
return new Response($this->twig->render(
248-
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException),
249-
array(
250-
'status_code' => $code,
251-
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
252-
'exception' => $exception,
253-
'logger' => $logger,
254-
'currentContent' => $currentContent,
255-
)
256-
));
245+
$code = $exception->getStatusCode();
246+
247+
return new JsonResponse(array(
248+
'response_type' => 'error',
249+
'message' => 'An exception was thrown.'
250+
), $code);
257251
}
258252
}
259253

0 commit comments

Comments
 (0)