Skip to content

Instantly share code, notes, and snippets.

@iturgeon
Created August 12, 2014 23:39
Show Gist options
  • Save iturgeon/4588221fc687008aed7f to your computer and use it in GitHub Desktop.
Save iturgeon/4588221fc687008aed7f to your computer and use it in GitHub Desktop.
Possible FuelPHP routing solution for dealing with 500s
<?
try
{
$response = Request::forge()->execute()->response();
}
catch (Exception $e)
{
$errorMap = [
'HttpNotFoundException' => '_404_',
'HttpServerErrorException' => '_500_',
];
$errorType = get_class($e);
$error = isset($errorMap[$errorType]) ? $errorMap[$errorType] : '';
$route = array_key_exists($error, Router::$routes) ? Router::$routes[$error]->translation : Config::get('routes.'.$error);
if($route instanceof Closure)
{
$response = $route();
if( ! $response instanceof Response)
{
$response = Response::forge($response);
}
}
elseif ($route)
{
$response = Request::forge($route, false)->execute()->response();
}
else
{
throw $e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment