File: /var/www/console.fixgini.com/bootstrap/app.php
<?php
use Illuminate\Support\Facades\App;
use Illuminate\Foundation\Application;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->statefulApi();
$middleware->alias([
'admin' => \App\Http\Middleware\CheckIfAdmin::class,
'buyer' => \App\Http\Middleware\CheckIfBuyer::class,
'seller' => \App\Http\Middleware\CheckIfSeller::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
if ($exceptions instanceof AuthenticationException) {
return response()->json([
'status' => 'error',
'message' => 'Bearer token is missing or invalid.'
], 401);
}
if ($exceptions instanceof NotFoundHttpException) {
return response()->json([
'status' => 'error',
'message' => 'Request URL not found.'
], 404);
}
if ($exceptions instanceof AuthorizationException || ($exceptions instanceof HttpException && $exceptions->getStatusCode() === 403)) {
return response()->json([
'status' => 'error',
'message' => 'Unathorization request URL.'
], 403);
}
if ($exceptions instanceof ConnectException) {
return response()->json([
'status' => 'error',
'message' => 'Internet connection occured.'
], 500);
}
if ($exceptions instanceof ServiceUnavailableHttpException && App::isDownForMaintenance()) {
return response()->json([
'status' => 'error',
'message' => 'Application in Maintenance mode.'
], 503);
}
})->create();