ldc-ovoteam/bootstrap/exceptions.php

34 lines
1 KiB
PHP

<?php
declare(strict_types=1);
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Uwil\LaravelCommon\Helpers\InertiaHelper;
return function (Exceptions $exceptions) {
$exceptions->render(function (HttpException $e, Request $request) {
$status = $e->getStatusCode();
return InertiaHelper::errorRender($request, $status);
});
$exceptions->report(function (\Throwable $e) {
if (app()->bound('sentry')) {
app('sentry')->captureException($e);
}
});
$exceptions->render(function (ValidationException $e, Request $request) {
$safeInput = Collection::make($request->all())
->except(['password', 'password_confirmation', 'current_password'])
->toArray();
return back()
->withInput($safeInput)
->withErrors($e->errors());
});
};