Updated documentation and added demo-project.

This commit is contained in:
Simon Sessingø
2016-09-26 14:37:54 +02:00
parent fab0d0641c
commit 980a4e9b6a
13 changed files with 359 additions and 3 deletions
@@ -0,0 +1,28 @@
<?php
namespace Demo\Handlers;
use Pecee\Handler\IExceptionHandler;
use Pecee\Http\Request;
use Pecee\SimpleRouter\RouterEntry;
class CustomExceptionHandler implements IExceptionHandler {
public function handleError( Request $request, RouterEntry $router = null, \Exception $error) {
// Return json errors if we encounter an error on /api.
if(stripos($request->getUri(), '/api') !== false) {
header('content-type: application/json');
echo json_encode([
'error' => $error->getMessage(),
'code' => $error->getCode()
]);
die();
}
// else we just throw the error
if($error->getCode() == 404) {
die(sprintf('An error occurred (%s):<br/>%s', $error->getCode(), $error->getMessage()));
}
}
}