]> BookStack Code Mirror - bookstack/blobdiff - app/Exceptions/Handler.php
settings.php: add missing french translation
[bookstack] / app / Exceptions / Handler.php
index 57e807db0e14d20014ebf13dea9469cdce87ea43..5260eb6cd88b95a5b75380eaa500ad7a33483e28 100644 (file)
@@ -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');
+    }
 }