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;
} 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');
+ }
}