mirror of
https://github.com/LinkStackOrg/LinkStack.git
synced 2025-04-06 22:51:03 +02:00
Enhance exception handling in the Handler class and improve error display in dashboard-error view
This commit is contained in:
parent
3c1ebbcbd2
commit
1cf1ab79d5
@ -42,28 +42,32 @@ class Handler extends ExceptionHandler
|
|||||||
|
|
||||||
$this->renderable(function (Throwable $e, Request $request) {
|
$this->renderable(function (Throwable $e, Request $request) {
|
||||||
|
|
||||||
try {
|
if ($e->getPrevious() instanceof \Illuminate\Session\TokenMismatchException) {
|
||||||
// Check if the request matches a specific route
|
|
||||||
if ($request->is('dashboard') ||
|
return redirect()->route('login')->withErrors(['email' => 'Your session has expired. Please log in again.']);
|
||||||
$request->is('dashboard/*') ||
|
|
||||||
$request->is('admin/*') ||
|
|
||||||
$request->is('studio/*')) {
|
|
||||||
|
|
||||||
// Handle 404 errors for this specific route
|
|
||||||
if ($e instanceof NotFoundHttpException) {
|
|
||||||
$message = "The page you are looking for was not found.";
|
|
||||||
return response()->view('errors.dashboard-error', compact('message'), 404);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle general exceptions for this specific route
|
try {
|
||||||
|
$patterns = ['dashboard', 'dashboard/*', 'admin/*', 'studio/*'];
|
||||||
|
|
||||||
|
if (collect($patterns)->contains(fn($pattern) => $request->is($pattern))) {
|
||||||
|
|
||||||
|
if ($e instanceof NotFoundHttpException) {
|
||||||
|
|
||||||
|
$message = "The page you are looking for was not found.";
|
||||||
|
|
||||||
|
return response()->view('errors.dashboard-error', compact('message'), 404);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$error = $e;
|
$error = $e;
|
||||||
$message = $e->getMessage();
|
$message = $e->getMessage();
|
||||||
|
|
||||||
return response()->view('errors.dashboard-error', compact(['error', 'message']), 500);
|
return response()->view('errors.dashboard-error', compact(['error', 'message']), 500);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default exception handling for other routes
|
|
||||||
return parent::render($request, $e);
|
|
||||||
} catch (Throwable $e) {}
|
} catch (Throwable $e) {}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -35,9 +35,14 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="alert alert-danger mb-0" role="alert">
|
<div class="alert alert-danger mb-0" role="alert">
|
||||||
@php
|
@php
|
||||||
|
try {
|
||||||
preg_match('/^(.*?)\s?\((.*?)\)$/', $message, $matches);
|
preg_match('/^(.*?)\s?\((.*?)\)$/', $message, $matches);
|
||||||
$outside = $matches[1];
|
$outside = $matches[1];
|
||||||
$inside = $matches[2];
|
$inside = $matches[2];
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
$outside = $message;
|
||||||
|
$inside = '';
|
||||||
|
}
|
||||||
@endphp
|
@endphp
|
||||||
<h4 class="alert-heading">{{$outside}}</h4>
|
<h4 class="alert-heading">{{$outside}}</h4>
|
||||||
<p>{{$inside}}</p>
|
<p>{{$inside}}</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user