12345678910111213141516171819202122 |
- <?php
- namespace demo\Errors;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- class HttpErrorHandler {
- // Error handlers receive exactly these arguments, in that order.
- public static function handle(HttpException $e, Request $request, $code) {
- $response = new Response("HTTP Error $code caught: skipping generic error handler.",
- // This status is ignored by Silex, which tries to ensure status code
- // consistency with the exception.
- Response::HTTP_NOT_FOUND,
- // But we can force it with this fake header, which is removed before
- // sending the response to the user agent.
- ['X-Status-Code' => Response::HTTP_OK]);
- return $response;
- }
- }
|