File tree 4 files changed +74
-2
lines changed
4 files changed +74
-2
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ public function handle($input, $output = null)
29
29
}
30
30
catch (Exception $ e )
31
31
{
32
- $ output ->writeln ((string ) $ e );
32
+ $ this ->reportException ($ e );
33
+
34
+ $ this ->renderException ($ output , $ e );
33
35
34
36
return 1 ;
35
37
}
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ public function handle($request)
34
34
}
35
35
catch (Exception $ e )
36
36
{
37
- throw $ e ;
37
+ $ this ->reportException ($ e );
38
+
39
+ return $ this ->renderException ($ request , $ e );
38
40
}
39
41
}
40
42
Original file line number Diff line number Diff line change
1
+ <?php namespace App \Infrastructure ;
2
+
3
+ use Exception ;
4
+ use Psr \Log \LoggerInterface ;
5
+ use Symfony \Component \Debug \ExceptionHandler as SymfonyDisplayer ;
6
+ use Illuminate \Contracts \Debug \ExceptionHandler as ExceptionHandlerContract ;
7
+
8
+ class ExceptionHandler implements ExceptionHandlerContract {
9
+
10
+ /**
11
+ * The log implementation.
12
+ *
13
+ * @var \Psr\Log\LoggerInterface
14
+ */
15
+ protected $ log ;
16
+
17
+ /**
18
+ * Create a new exception handler instance.
19
+ *
20
+ * @param \Psr\Log\LoggerInterface $log
21
+ * @return void
22
+ */
23
+ public function __construct (LoggerInterface $ log )
24
+ {
25
+ $ this ->log = $ log ;
26
+ }
27
+
28
+ /**
29
+ * Report or log an exception.
30
+ *
31
+ * @param \Exception $e
32
+ * @return void
33
+ */
34
+ public function report (Exception $ e )
35
+ {
36
+ $ this ->log ->error ((string ) $ e );
37
+ }
38
+
39
+ /**
40
+ * Render an exception into a response.
41
+ *
42
+ * @param \Illuminate\Http\Request $request
43
+ * @param \Exception $e
44
+ * @return \Symfony\Component\HttpFoundation\Response
45
+ */
46
+ public function render ($ request , Exception $ e )
47
+ {
48
+ return (new SymfonyDisplayer )->createResponse ($ e );
49
+ }
50
+
51
+ /**
52
+ * Render an exception to the console.
53
+ *
54
+ * @param \Symfony\Component\Console\Output\OutputInterface $output
55
+ * @param \Exception $e
56
+ * @return void
57
+ */
58
+ public function renderForConsole ($ output , Exception $ e )
59
+ {
60
+ $ output ->writeln ((string ) $ e );
61
+ }
62
+
63
+ }
Original file line number Diff line number Diff line change 36
36
'App\Console\Kernel '
37
37
);
38
38
39
+ $ app ->singleton (
40
+ 'Illuminate\Contracts\Debug\ExceptionHandler ' ,
41
+ 'App\Infrastructure\ExceptionHandler '
42
+ );
43
+
39
44
/*
40
45
|--------------------------------------------------------------------------
41
46
| Return The Application
You can’t perform that action at this time.
0 commit comments