PHP code example of jenky / api-error
1. Go to this page and download the library: Download jenky/api-error 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/ */
jenky / api-error example snippets
use Jenky\ApiError\Formatter\GenericErrorFormatter;
use Jenky\ApiError\Transformer\ChainTransformer;
$transformer = new ChainTransformer([
// ... list of transformers
])
$formatter = new GenericErrorFormatter(true, $transformer);
// or simply without transformer and debug is off
$formatter = new GenericErrorFormatter();
/** @var \Throwable $exception */
return \json_encode($formatter->format($exception));
new GenericFormatter(transformer: new MyExceptionTransformer);
// or
new Rfc7807ErrorFormatter(transformer: new MyExceptionTransformer);