X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ec17bd86085fb5ac94f3bd4c2fe216fb3b45c6dd..refs/pull/446/head:/app/Exceptions/Handler.php diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 57e807db0..5260eb6cd 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,9 +3,9 @@ namespace BookStack\Exceptions; use Exception; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Auth\AuthenticationException; +use Illuminate\Validation\ValidationException; use Illuminate\Database\Eloquent\ModelNotFoundException; -use PhpSpec\Exception\Example\ErrorException; use Symfony\Component\HttpKernel\Exception\HttpException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Auth\Access\AuthorizationException; @@ -87,4 +87,20 @@ class Handler extends ExceptionHandler } while ($e = $e->getPrevious()); return $message; } + + /** + * 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'); + } }