mirror of
https://github.com/LinkStackOrg/LinkStack.git
synced 2025-02-15 03:20:52 +01:00
Implement custom error handling for dashboard routes
This commit is contained in:
parent
ec82e775a2
commit
7a02d438eb
@ -3,7 +3,9 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Request;
|
||||
use Throwable;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -38,10 +40,32 @@ class Handler extends ExceptionHandler
|
||||
//
|
||||
});
|
||||
|
||||
$this->renderable(function (\Exception $e) {
|
||||
if ($e->getPrevious() instanceof \Illuminate\Session\TokenMismatchException) {
|
||||
return redirect()->route('login');
|
||||
};
|
||||
$this->renderable(function (Throwable $e, Request $request) {
|
||||
|
||||
try {
|
||||
// Check if the request matches a specific route
|
||||
if ($request->is('dashboard') ||
|
||||
$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
|
||||
|
||||
$error = $e;
|
||||
$message = $e->getMessage();
|
||||
return response()->view('errors.dashboard-error', compact(['error', 'message']), 500);
|
||||
}
|
||||
|
||||
// Default exception handling for other routes
|
||||
return parent::render($request, $e);
|
||||
} catch (Throwable $e) {}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
67
resources/views/errors/dashboard-error.blade.php
Normal file
67
resources/views/errors/dashboard-error.blade.php
Normal file
@ -0,0 +1,67 @@
|
||||
@extends('layouts.sidebar')
|
||||
|
||||
@section('content')
|
||||
<div class="conatiner-fluid content-inner mt-n5 py-0">
|
||||
<div class="row">
|
||||
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="card rounded mb-0">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
|
||||
<section class="">
|
||||
<h2 class="mb-4 card-header"><i class="bi bi-person"> Error 500</i></h2>
|
||||
<div style="min-height: calc(100vh - 340px);" class="card-body mt-n5 p-0 p-md-3 d-flex flex-column justify-content-center align-items-center">
|
||||
|
||||
<div class="d-flex flex-row align-items-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-12 text-center">
|
||||
<span class="display-1 d-block">500</span>
|
||||
<div class="mb-4 lead">HTTP Error 500 - Internal Server Error</div>
|
||||
<a href="{{url('dashboard')}}" class="btn btn-primary">Back to Home</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if(auth()->check() && auth()->user()->role == 'admin')
|
||||
<div class="d-flex flex-row align-items-center mt-5">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert-danger mb-0" role="alert">
|
||||
@php
|
||||
preg_match('/^(.*?)\s?\((.*?)\)$/', $message, $matches);
|
||||
$outside = $matches[1];
|
||||
$inside = $matches[2];
|
||||
@endphp
|
||||
<h4 class="alert-heading">{{$outside}}</h4>
|
||||
<p>{{$inside}}</p>
|
||||
@php dump($error); @endphp
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
Loading…
x
Reference in New Issue
Block a user