mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-22 16:51:20 +00:00
34 lines
883 B
PHP
34 lines
883 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Api\Rest\V1\Core;
|
|
|
|
use CodeIgniter\Debug\Exceptions;
|
|
use Throwable;
|
|
|
|
class RestApiExceptions extends Exceptions
|
|
{
|
|
protected function render(Throwable $exception, int $statusCode): void
|
|
{
|
|
header('Content-Type: application/json');
|
|
$data = [
|
|
'status' => $statusCode,
|
|
'error' => $statusCode,
|
|
'messages' => [
|
|
'error' => 'Unexpected error',
|
|
],
|
|
];
|
|
if (ENVIRONMENT === 'development') {
|
|
$data['messages'] = array_merge($data['messages'], [
|
|
'message' => $exception->getMessage(),
|
|
'file' => $exception->getFile(),
|
|
'line' => $exception->getLine(),
|
|
'trace' => $exception->getTrace(),
|
|
]);
|
|
}
|
|
|
|
echo json_encode($data);
|
|
}
|
|
}
|