]> BookStack Code Mirror - bookstack/blobdiff - app/Exceptions/Handler.php
Finished refactor of entity repos
[bookstack] / app / Exceptions / Handler.php
index 57e807db0e14d20014ebf13dea9469cdce87ea43..c64f0cd1fc7941ac15bba50cb7d16b0ce1817d6c 100644 (file)
@@ -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');
+    }
 }