1. Go to this page and download the library: Download lalu/jer 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/ */
use LaLu\JER\ExceptionHandler;
class Handler extends ExceptionHandler
{
// ...
}
use LaLu\JER\ExceptionHandler;
class Handler extends ExceptionHandler
{
public $meta = [
'meta_field_1' => 'meta_value_1',
// ...
];
// ...
}
use LaLu\JER\ExceptionHandler;
class Handler extends ExceptionHandler
{
public function beforeRender($request, Exception $exception)
{
$this->meta = [
'meta_field_1' => 'meta_value_1',
// ...
];
}
// ...
}
use LaLu\JER\ExceptionHandler;
use LaLu\JER\Error;
class Handler extends ExceptionHandler
{
// ...
/**
* Get exception jsonapi data.
*
* @param \Exception $exception
*
* @return array
*/
protected function getExceptionError(Exception $exception)
{
if ($exception instanceof \Exception\You\Want) {
// status must be an integer and is a HTTP error status code
$status = 400;
// headers must be an array of key value
$headers = [];
$content = [
'title' => 'Your exception custom title',
'detail' => 'Your exception custom detail',
];
// error can be an instance/array items of \LaLu\JER\Error or array of error array
$error = new Error(['version' => $this->jsonapiVersion], $content);
$error->status = '400';
// ...
return [$status, $error, $headers];
} elseif ($exception instanceof \Other\Exception) {
return [400, [['title' => 'Your request is bad request']], []];
} else {
return parent::getExceptionError($exception);
}
}
}