<?php
// ApiJsonErrorRenderer.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Exception;use Slim\Exception\HttpException;use Slim\Interfaces\ErrorRendererInterface;use Throwable;class ApiJsonErrorRenderer implements ErrorRendererInterface{public function __invoke(Throwable $exception,bool $displayErrorDetails):string{$result=['type'=>get_class($exception),'code'=>$exception->getCode()!=0?$exception->getCode():500,'message'=>($displayErrorDetails&&$exception->getCode()!=0)?$exception->getMessage():'Server error',];if($displayErrorDetails){if(method_exists($exception,'getDescription')&&!empty($exception->getDescription()))$result['description']=$exception->getDescription();$result['file']=$exception->getFile();$result['line']=$exception->getLine();}return json_encode($result);}}