Skip to content

Commit

Permalink
fix: move to bootstrap/app.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiCO2k committed Apr 17, 2024
1 parent 8089373 commit d035c15
Show file tree
Hide file tree
Showing 5 changed files with 582 additions and 549 deletions.
33 changes: 0 additions & 33 deletions app/Exceptions/Handler.php

This file was deleted.

23 changes: 19 additions & 4 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Inertia\Inertia;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
Expand All @@ -15,8 +19,19 @@
\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
]);
})
->withSingletons([
Illuminate\Contracts\Debug\ExceptionHandler::class => \App\Exceptions\Handler::class,
])
->withExceptions()
->withExceptions(function (Exceptions $exceptions) {
$exceptions->respond(function (Response $response, Throwable $exception, Request $request) {
if (! app()->environment(['local', 'testing']) && in_array($response->getStatusCode(), [500, 503, 404, 403])) {
return Inertia::render('Error', ['status' => $response->getStatusCode()])
->toResponse($request)
->setStatusCode($response->getStatusCode());
} elseif ($response->getStatusCode() === 419) {
return back()->with([
'message' => 'The page expired, please try again.',
]);
}

return $response;
});
})
->create();
Loading

0 comments on commit d035c15

Please sign in to comment.