fix(handler): fallback to HTML when Vite manifest missing during error rendering

This commit is contained in:
F4ilji
2026-07-06 13:41:52 +05:00
parent 9bac98d175
commit 3ee875a6db
+40 -6
View File
@@ -61,9 +61,7 @@ class Handler extends AbstractHandler
}
if (! app()->environment(['local', 'testing'])) {
return Inertia::render('Error', ['status' => $statusCode])
->toResponse($request)
->setStatusCode($statusCode);
return $this->renderInertiaError($request, $statusCode);
}
} elseif ($statusCode === 419) {
return back()->with([
@@ -74,6 +72,33 @@ class Handler extends AbstractHandler
return $response;
}
/**
* Render Inertia error page with Vite manifest fallback.
*/
private function renderInertiaError(Request $request, int $statusCode)
{
try {
return Inertia::render('Error', ['status' => $statusCode])
->toResponse($request)
->setStatusCode($statusCode);
} catch (\Throwable $e) {
$messages = [
503 => 'Сервис временно недоступен. Попробуйте позже.',
500 => 'Внутренняя ошибка сервера.',
404 => 'Запрашиваемая страница не найдена.',
403 => 'У вас нет доступа к этой странице.',
];
$message = $messages[$statusCode] ?? 'Произошла ошибка.';
return response(
'<!DOCTYPE html><html><head><title>Error ' . $statusCode . '</title></head>'
. '<body style="font-family:sans-serif;text-align:center;padding:50px">'
. '<h1>' . $statusCode . '</h1><p>' . $message . '</p></body></html>',
$statusCode
);
}
}
/**
* Check if the request is for a dashboard route.
*/
@@ -110,9 +135,18 @@ class Handler extends AbstractHandler
]);
}
return Inertia::render('Dashboard/DashboardError', $props)
->toResponse($request)
->setStatusCode($statusCode);
try {
return Inertia::render('Dashboard/DashboardError', $props)
->toResponse($request)
->setStatusCode($statusCode);
} catch (\Throwable $e) {
return response(
'<!DOCTYPE html><html><head><title>Error ' . $statusCode . '</title></head>'
. '<body style="font-family:sans-serif;text-align:center;padding:50px">'
. '<h1>' . $statusCode . '</h1><p>' . ($props['message'] ?? 'Ошибка') . '</p></body></html>',
$statusCode
);
}
}
/**