HttpErrorHandler.php 792 B

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