store-manage/app/Exceptions/Handler.php

48 lines
1.3 KiB
PHP

<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Illuminate\Http\{Request};
use Illuminate\Validation\ValidationException;
use Slowlyo\OwlAdmin\Exceptions\AdminException;
class Handler extends ExceptionHandler
{
/**
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
protected $dontReport = [
AdminException::class,
RuntimeException::class,
];
/**
* Register the exception handling callbacks for the application.
*/
public function register(): void
{
$this->renderable(function (RuntimeException $e, Request $request) {
return response(['code' => $e->getCode(), 'message' => $e->getMessage()], $e->getHttpStatusCode());
});
}
protected function invalidJson($request, ValidationException $exception)
{
return response()->json([
'code' => $exception->status,
'message' => $exception->getMessage(),
'errors' => $exception->errors(),
], $exception->status);
}
}