aboutsummaryrefslogtreecommitdiff
path: root/app/Exceptions
diff options
context:
space:
mode:
Diffstat (limited to 'app/Exceptions')
-rw-r--r--app/Exceptions/Handler.php39
1 files changed, 30 insertions, 9 deletions
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php
index 8d0b13e..21c9784 100644
--- a/app/Exceptions/Handler.php
+++ b/app/Exceptions/Handler.php
@@ -3,8 +3,8 @@
namespace App\Exceptions;
use Exception;
-use Symfony\Component\HttpKernel\Exception\HttpException;
-use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
+use Illuminate\Auth\AuthenticationException;
+use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
@@ -14,7 +14,12 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontReport = [
- HttpException::class,
+ \Illuminate\Auth\AuthenticationException::class,
+ \Illuminate\Auth\Access\AuthorizationException::class,
+ \Symfony\Component\HttpKernel\Exception\HttpException::class,
+ \Illuminate\Database\Eloquent\ModelNotFoundException::class,
+ \Illuminate\Session\TokenMismatchException::class,
+ \Illuminate\Validation\ValidationException::class,
];
/**
@@ -22,23 +27,39 @@ class Handler extends ExceptionHandler
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
- * @param \Exception $e
+ * @param \Exception $exception
* @return void
*/
- public function report(Exception $e)
+ public function report(Exception $exception)
{
- return parent::report($e);
+ parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
- * @param \Exception $e
+ * @param \Exception $exception
* @return \Illuminate\Http\Response
*/
- public function render($request, Exception $e)
+ public function render($request, Exception $exception)
{
- return parent::render($request, $e);
+ return parent::render($request, $exception);
+ }
+
+ /**
+ * 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');
}
}