Skip to content

Commit

Permalink
fix test's warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
PrabuckiDominik committed Aug 7, 2024
1 parent 28ec851 commit f283510
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
19 changes: 19 additions & 0 deletions app/Exceptions/ErrorHandlingConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Exceptions;

use Exception;
use Symfony\Component\HttpFoundation\Response;

class ErrorHandlingConfig extends Exception
{
public const int HTTP_SESSION_EXPIRED = 419;
public const array HANDLED_ERROR_CODES = [
Response::HTTP_FORBIDDEN,
Response::HTTP_INTERNAL_SERVER_ERROR,
Response::HTTP_SERVICE_UNAVAILABLE,
Response::HTTP_NOT_FOUND,
];
}
13 changes: 3 additions & 10 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@

declare(strict_types=1);

use App\Exceptions\ErrorHandlingConfig;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Symfony\Component\HttpFoundation\Response;

const HTTP_SESSION_EXPIRED = 419;
const HANDLED_ERROR_CODES = [
Response::HTTP_FORBIDDEN,
Response::HTTP_INTERNAL_SERVER_ERROR,
Response::HTTP_SERVICE_UNAVAILABLE,
Response::HTTP_NOT_FOUND,
];

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__ . "/../routes/web.php",
Expand All @@ -28,11 +21,11 @@
})
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->respond(function (Response $response, Throwable $exception, Request $request): Response {
if (!app()->environment(["local", "testing"]) && in_array($response->getStatusCode(), HANDLED_ERROR_CODES, true)) {
if (!app()->environment(["local", "testing"]) && in_array($response->getStatusCode(), ErrorHandlingConfig::HANDLED_ERROR_CODES, true)) {
return Inertia::render("Errors/Error", ["status" => $response->getStatusCode()])
->toResponse($request)
->setStatusCode($response->getStatusCode());
} elseif ($response->getStatusCode() === HTTP_SESSION_EXPIRED) {
} elseif ($response->getStatusCode() === ErrorHandlingConfig::HTTP_SESSION_EXPIRED) {
return back()->with([
"message" => "The page expired, please try again.",
]);
Expand Down

0 comments on commit f283510

Please sign in to comment.