Files
fotospiel-app/app/Exceptions/Handler.php
2025-10-07 11:52:03 +02:00

66 lines
2.2 KiB
PHP

<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
class Handler extends ExceptionHandler
{
/**
* The list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*/
public function register(): void
{
$this->reportable(function (Throwable $e) {
//
});
}
public function render($request, Throwable $e)
{
\Illuminate\Support\Facades\Log::info('Handler render called', ['inertia' => $request->inertia(), 'exception' => get_class($e), 'url' => $request->url()]);
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
\Illuminate\Support\Facades\Log::error('Route not found (404)', [
'url' => $request->url(),
'method' => $request->method(),
'referer' => $request->header('referer'),
'user_agent' => $request->header('user-agent')
]);
}
if ($request->inertia()) {
if ($e instanceof ValidationException) {
\Illuminate\Support\Facades\Log::info('ValidationException in Inertia', ['errors' => $e->errors(), 'url' => $request->url()]);
return response()->json([
'message' => 'The given data was invalid.',
'errors' => $e->errors(),
], 422)->header('X-Inertia-Error', 'true');
}
if ($e instanceof \Exception) {
\Illuminate\Support\Facades\Log::info('Exception in Inertia', ['message' => $e->getMessage(), 'url' => $request->url()]);
return response()->json([
'message' => 'Registrierung fehlgeschlagen.',
'errors' => ['general' => $e->getMessage()],
], 500)->header('X-Inertia-Error', 'true');
}
}
return parent::render($request, $e);
}
}