Skip to content

Commit 35a5501

Browse files
committed
Review + Fix Exception Mail
1 parent 8a24f9e commit 35a5501

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

app/Exceptions/Handler.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use App\Mail\ExceptionOccured;
66
use Illuminate\Auth\AuthenticationException;
77
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
8-
use Illuminate\Http\Request;
98
use Illuminate\Http\Response;
109
use Illuminate\Support\Facades\Log;
1110
use Illuminate\Support\Facades\Mail;
12-
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
11+
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
12+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1313
use Throwable;
1414

1515
class Handler extends ExceptionHandler
@@ -117,14 +117,11 @@ protected function unauthenticated($request, AuthenticationException $exception)
117117
public function sendEmail(Throwable $exception): void
118118
{
119119
try {
120-
$content['message'] = $exception->getMessage();
121-
$content['file'] = $exception->getFile();
122-
$content['line'] = $exception->getLine();
123-
$content['trace'] = $exception->getTrace();
124-
$content['url'] = request()->url();
125-
$content['body'] = request()->all();
126-
$content['ip'] = request()->ip();
127-
Mail::send(new ExceptionOccured($content));
120+
$e = FlattenException::createFromThrowable($exception);
121+
$handler = new HtmlErrorRenderer(true);
122+
$css = $handler->getStylesheet();
123+
$content = $handler->getBody($e);
124+
Mail::send(new ExceptionOccured($content, $css));
128125
} catch (Throwable $exception) {
129126
Log::error($exception);
130127
}

app/Http/Middleware/CheckCurrentUser.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44

55
use Closure;
66
use Illuminate\Http\Request;
7-
use Illuminate\Http\Response;
87
use Illuminate\Support\Facades\Auth;
98
use Illuminate\Support\Facades\Route;
9+
use Symfony\Component\HttpFoundation\Response;
1010

1111
class CheckCurrentUser
1212
{
1313
/**
1414
* Handle an incoming request.
1515
*
1616
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
17-
*
18-
* @return \Illuminate\Http\Response
1917
*/
20-
public function handle(Request $request, Closure $next)
18+
public function handle(Request $request, Closure $next): Response
2119
{
2220
if (! $request->user()) {
2321
abort(403, 'Unauthorized action.');

app/Http/Middleware/CheckIsUserActivated.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66
use Carbon\Carbon;
77
use Closure;
88
use Illuminate\Http\Request;
9-
use Illuminate\Http\Response;
109
use Illuminate\Support\Facades\Auth;
1110
use Illuminate\Support\Facades\Log;
1211
use Illuminate\Support\Facades\Route;
12+
use Symfony\Component\HttpFoundation\Response;
1313

1414
class CheckIsUserActivated
1515
{
1616
/**
1717
* Handle an incoming request.
1818
*
1919
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
20-
*
21-
* @return \Illuminate\Http\Response
2220
*/
23-
public function handle(Request $request, Closure $next)
21+
public function handle(Request $request, Closure $next): Response
2422
{
2523
if (config('settings.activation')) {
2624
$user = Auth::user();

app/Mail/ExceptionOccured.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ class ExceptionOccured extends Mailable
1111
use Queueable, SerializesModels;
1212

1313
private $content;
14+
private $css;
1415

1516
/**
1617
* Create a new message instance.
1718
*
1819
* @return void
1920
*/
20-
public function __construct($content)
21+
public function __construct($content, $css)
2122
{
2223
$this->content = $content;
24+
$this->css = $css;
2325
}
2426

2527
/**
@@ -61,6 +63,7 @@ public function build()
6163
->bcc($bccEmails)
6264
->subject($subject)
6365
->view(config('exceptions.emailExceptionView'))
66+
->with('css', $this->css)
6467
->with('content', $this->content);
6568
}
6669
}
+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
{!! $content !!}
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<style>
7+
{!! $css ?? '' !!}
8+
</style>
9+
</head>
10+
11+
<body>
12+
{!! $content ?? '' !!}
13+
</body>
14+
15+
</html>

vite.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import viteImagemin from "vite-plugin-imagemin";
1515
import vue from "@vitejs/plugin-vue";
1616
import Pages from "vite-plugin-pages";
1717
import generateSitemap from "vite-plugin-pages-sitemap";
18-
// import "jquery";
19-
// import $ from " jquery";
20-
// import jQuery from "jquery";
18+
import "jquery";
19+
import $ from "jquery";
20+
import jQuery from "jquery";
2121

2222
export default ({ mode }) => {
2323
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

0 commit comments

Comments
 (0)