mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
Updated documentation and added demo-project.
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user