4
4
5
5
use App \Mail \ExceptionOccured ;
6
6
use Exception ;
7
- use Illuminate \Http \Request ;
8
7
use Illuminate \Auth \AuthenticationException ;
9
8
use Illuminate \Foundation \Exceptions \Handler as ExceptionHandler ;
10
9
use Illuminate \Support \Facades \Log ;
11
10
use Mail ;
12
11
use Response ;
13
- use Symfony \Component \Debug \ExceptionHandler as SymfonyExceptionHandler ;
14
12
use Symfony \Component \Debug \Exception \FlattenException ;
13
+ use Symfony \Component \Debug \ExceptionHandler as SymfonyExceptionHandler ;
15
14
16
15
class Handler extends ExceptionHandler
17
16
{
@@ -34,15 +33,15 @@ class Handler extends ExceptionHandler
34
33
*
35
34
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
36
35
*
37
- * @param \Exception $exception
36
+ * @param \Exception $exception
37
+ *
38
38
* @return void
39
39
*/
40
40
public function report (Exception $ exception )
41
41
{
42
-
43
42
$ enableEmailExceptions = config ('exceptions.emailExceptionEnabled ' );
44
43
45
- if ($ enableEmailExceptions === "" ) {
44
+ if ($ enableEmailExceptions === '' ) {
46
45
$ enableEmailExceptions = config ('exceptions.emailExceptionEnabledDefault ' );
47
46
}
48
47
@@ -56,25 +55,24 @@ public function report(Exception $exception)
56
55
/**
57
56
* Render an exception into an HTTP response.
58
57
*
59
- * @param \Illuminate\Http\Request $request
60
- * @param \Exception $exception
58
+ * @param \Illuminate\Http\Request $request
59
+ * @param \Exception $exception
60
+ *
61
61
* @return \Illuminate\Http\Response
62
62
*/
63
63
public function render ($ request , Exception $ exception )
64
64
{
65
-
66
65
$ userLevelCheck = $ exception instanceof \jeremykenedy \LaravelRoles \Exceptions \RoleDeniedException ||
67
66
$ exception instanceof \jeremykenedy \LaravelRoles \Exceptions \RoleDeniedException ||
68
67
$ exception instanceof \jeremykenedy \LaravelRoles \Exceptions \PermissionDeniedException ||
69
68
$ exception instanceof \jeremykenedy \LaravelRoles \Exceptions \LevelDeniedException;
70
69
71
70
if ($ userLevelCheck ) {
72
-
73
71
if ($ request ->expectsJson ()) {
74
- return Response::json (array (
75
- 'error ' => 403 ,
76
- 'message ' => 'Unauthorized. '
77
- ) , 403 );
72
+ return Response::json ([
73
+ 'error ' => 403 ,
74
+ 'message ' => 'Unauthorized. ' ,
75
+ ] , 403 );
78
76
}
79
77
80
78
abort (403 );
@@ -83,12 +81,12 @@ public function render($request, Exception $exception)
83
81
return parent ::render ($ request , $ exception );
84
82
}
85
83
86
-
87
84
/**
88
85
* Convert an authentication exception into an unauthenticated response.
89
86
*
90
- * @param \Illuminate\Http\Request $request
91
- * @param \Illuminate\Auth\AuthenticationException $exception
87
+ * @param \Illuminate\Http\Request $request
88
+ * @param \Illuminate\Auth\AuthenticationException $exception
89
+ *
92
90
* @return \Illuminate\Http\Response
93
91
*/
94
92
protected function unauthenticated ($ request , AuthenticationException $ exception )
@@ -103,24 +101,20 @@ protected function unauthenticated($request, AuthenticationException $exception)
103
101
/**
104
102
* Sends an email upon exception.
105
103
*
106
- * @param \Exception $exception
104
+ * @param \Exception $exception
105
+ *
107
106
* @return void
108
107
*/
109
108
public function sendEmail (Exception $ exception )
110
109
{
111
110
try {
112
-
113
111
$ e = FlattenException::create ($ exception );
114
112
$ handler = new SymfonyExceptionHandler ();
115
113
$ html = $ handler ->getHtml ($ e );
116
114
117
115
Mail::send (new ExceptionOccured ($ html ));
118
-
119
116
} catch (Exception $ exception ) {
120
-
121
117
Log::error ($ exception );
122
-
123
118
}
124
119
}
125
-
126
120
}
0 commit comments