From 33ad0c14d168d36a4e7ad42dc6aa6a37a7335849 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 25 Sep 2016 23:56:46 +0200 Subject: Change from lumen 5.2 to laravel 5.3 (Resolves #1) --- app/Exceptions/Handler.php | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'app/Exceptions/Handler.php') diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 8d0b13e..21c9784 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,8 +3,8 @@ namespace App\Exceptions; use Exception; -use Symfony\Component\HttpKernel\Exception\HttpException; -use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; +use Illuminate\Auth\AuthenticationException; +use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; class Handler extends ExceptionHandler { @@ -14,7 +14,12 @@ class Handler extends ExceptionHandler * @var array */ protected $dontReport = [ - HttpException::class, + \Illuminate\Auth\AuthenticationException::class, + \Illuminate\Auth\Access\AuthorizationException::class, + \Symfony\Component\HttpKernel\Exception\HttpException::class, + \Illuminate\Database\Eloquent\ModelNotFoundException::class, + \Illuminate\Session\TokenMismatchException::class, + \Illuminate\Validation\ValidationException::class, ]; /** @@ -22,23 +27,39 @@ class Handler extends ExceptionHandler * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param \Exception $e + * @param \Exception $exception * @return void */ - public function report(Exception $e) + public function report(Exception $exception) { - return parent::report($e); + parent::report($exception); } /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request - * @param \Exception $e + * @param \Exception $exception * @return \Illuminate\Http\Response */ - public function render($request, Exception $e) + public function render($request, Exception $exception) { - return parent::render($request, $e); + return parent::render($request, $exception); + } + + /** + * Convert an authentication exception into an unauthenticated response. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Auth\AuthenticationException $exception + * @return \Illuminate\Http\Response + */ + protected function unauthenticated($request, AuthenticationException $exception) + { + if ($request->expectsJson()) { + return response()->json(['error' => 'Unauthenticated.'], 401); + } + + return redirect()->guest('login'); } } -- cgit v1.2.3