Browse Source

Return JSON for unauthenticated AJAX requests

Joseph Silber 8 years ago
parent
commit
8e7672fc04
1 changed files with 1 additions and 1 deletions
  1. 1 1
      app/Exceptions/Handler.php

+ 1 - 1
app/Exceptions/Handler.php

@@ -56,7 +56,7 @@ class Handler extends ExceptionHandler
     protected function unauthenticated($request, AuthenticationException $e)
     {
         if ($request->ajax() || $request->wantsJson()) {
-            return response('Unauthorized.', 401);
+            return response()->json(['error' => 'Unauthenticated.'], 401);
         } else {
             return redirect()->guest('login');
         }