PHP code example of per-seo / jsonerror
1. Go to this page and download the library: Download per-seo/jsonerror library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
per-seo / jsonerror example snippets
'settings_error' => [
'reporting' => ['E_ALL', '~E_NOTICE'],
'display_error_details' => true,
'log_errors' => true,
'log_error_details' => true
]
use Psr\Container\ContainerInterface;
use Slim\App;
use Slim\Middleware\ErrorMiddleware;
use PerSeo\ErrorRenderer\JsonError;
ErrorMiddleware::class => function (ContainerInterface $container) {
$app = $container->get(App::class);
$settings = ($container->has('settings_error') ? $container->get('settings_error') : [
'reporting' => ['E_ALL','~E_NOTICE'],
'display_error_details' => true,
'log_errors' => true,
'log_error_details' => true
]);
$errorMiddleware = new ErrorMiddleware(
$app->getCallableResolver(),
$app->getResponseFactory(),
(bool)$settings['display_error_details'],
(bool)$settings['log_errors'],
(bool)$settings['log_error_details']
);
$errorHandler = $errorMiddleware->getDefaultErrorHandler();
$errorHandler->registerErrorRenderer('application/json', JsonError::class);
$errorHandler->forceContentType('application/json');
return $errorMiddleware;
}