Created
June 27, 2014 07:36
-
-
Save tournasdim/171b443065936bbb5ef3 to your computer and use it in GitHub Desktop.
A simple example how to handle errors in Silex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |
$app->error(function (\Exception $e) use ($app) { | |
if ($e instanceof NotFoundHttpException) { | |
return $app->json(array('error' => 'Page Not Found'), 404); | |
} | |
$code = ($e instanceof HttpException) ? $e->getStatusCode() : 500; | |
return $app->json(array('error' => $e->getMessage()), $code); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment