45 lines
1.4 KiB
PHP
45 lines
1.4 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();
|
|
|
|
if ($request->isAttemptingPrecognition() && $status === 204) {
|
|
return response('', 204, $e->getHeaders());
|
|
}
|
|
|
|
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) {
|
|
if ($request->wantsJson() || $request->isAttemptingPrecognition()) {
|
|
return response()->json([
|
|
'message' => $e->getMessage(),
|
|
'errors' => $e->errors(),
|
|
], $e->status);
|
|
}
|
|
|
|
$safeInput = Collection::make($request->all())
|
|
->except(['password', 'password_confirmation', 'current_password'])
|
|
->toArray();
|
|
|
|
return back()
|
|
->withInput($safeInput)
|
|
->withErrors($e->errors());
|
|
});
|
|
};
|