diff --git a/src/app/Exceptions/CustomHandler.php b/src/app/Exceptions/CustomHandler.php index eb584a1..9dfc8fb 100644 --- a/src/app/Exceptions/CustomHandler.php +++ b/src/app/Exceptions/CustomHandler.php @@ -2,14 +2,21 @@ namespace Omatech\Mage\App\Exceptions; +use Illuminate\Contracts\Container\Container; use Throwable; -use Illuminate\Foundation\Exceptions\Handler; +use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract; use Illuminate\Support\Facades\Route; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Illuminate\Database\Eloquent\ModelNotFoundException; -class CustomHandler extends Handler +class CustomHandler implements ExceptionHandlerContract { + public function __construct(Container $container, ExceptionHandlerContract $appExceptionHandler) + { + $this->container = $container; + $this->appExceptionHandler = $appExceptionHandler; + } + /** * Render an exception into an HTTP response. * @@ -44,12 +51,12 @@ public function render($request, Throwable $exception) if ($request->route()->getName() == 'mage.auth.login') { return redirect()->route('mage.auth.login')->with('status', 'unauthorized'); } - + return $this->exception(401, $request, $exception); } } - return parent::render($request, $exception); + return $this->appExceptionHandler->render($request, $e); } private function exception($code, $request, $exception) @@ -63,4 +70,19 @@ private function exception($code, $request, $exception) return Route::respondWithRoute("mage.error$code", $request); } + + public function report(Throwable $e) + { + $this->appExceptionHandler->report($e); + } + + public function renderForConsole($output, Throwable $e) + { + $this->appExceptionHandler->renderForConsole($output, $e); + } + + public function shouldReport(Throwable $e) + { + return $this->appExceptionHandler->shouldReport($e); + } } diff --git a/src/app/Providers/ExceptionServiceProvider.php b/src/app/Providers/ExceptionServiceProvider.php index f9cbad5..0541d21 100644 --- a/src/app/Providers/ExceptionServiceProvider.php +++ b/src/app/Providers/ExceptionServiceProvider.php @@ -2,15 +2,21 @@ namespace Omatech\Mage\App\Providers; -use Illuminate\Support\Facades\Gate; +use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract; use Illuminate\Support\ServiceProvider; use Omatech\Mage\App\Exceptions\CustomHandler; -use Illuminate\Contracts\Debug\ExceptionHandler; class ExceptionServiceProvider extends ServiceProvider { public function register() { - $this->app->bind(ExceptionHandler::class, CustomHandler::class); + $appExceptionHandler = $this->app->make(ExceptionHandlerContract::class); + + $this->app->singleton( + ExceptionHandlerContract::class, + function ($app) use ($appExceptionHandler) { + return new CustomHandler($app, $appExceptionHandler); + } + ); } }