diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ae7c4cc3..000510a5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -29,7 +29,9 @@ class Kernel extends ConsoleKernel { } catch (Exception $e) { - $output->writeln((string) $e); + $this->reportException($e); + + $this->renderException($output, $e); return 1; } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 4ddb0500..45e5108e 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -34,7 +34,9 @@ class Kernel extends HttpKernel { } catch (Exception $e) { - throw $e; + $this->reportException($e); + + return $this->renderException($request, $e); } } diff --git a/app/Infrastructure/ExceptionHandler.php b/app/Infrastructure/ExceptionHandler.php new file mode 100644 index 00000000..bb3553af --- /dev/null +++ b/app/Infrastructure/ExceptionHandler.php @@ -0,0 +1,63 @@ +log = $log; + } + + /** + * Report or log an exception. + * + * @param \Exception $e + * @return void + */ + public function report(Exception $e) + { + $this->log->error((string) $e); + } + + /** + * Render an exception into a response. + * + * @param \Illuminate\Http\Request $request + * @param \Exception $e + * @return \Symfony\Component\HttpFoundation\Response + */ + public function render($request, Exception $e) + { + return (new SymfonyDisplayer)->createResponse($e); + } + + /** + * Render an exception to the console. + * + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param \Exception $e + * @return void + */ + public function renderForConsole($output, Exception $e) + { + $output->writeln((string) $e); + } + +} diff --git a/bootstrap/app.php b/bootstrap/app.php index 66bdfdf5..c757cd3f 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -36,6 +36,11 @@ $app->singleton( 'App\Console\Kernel' ); +$app->singleton( + 'Illuminate\Contracts\Debug\ExceptionHandler', + 'App\Infrastructure\ExceptionHandler' +); + /* |-------------------------------------------------------------------------- | Return The Application