2015-06-01 15:43:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
2014-11-18 22:48:38 -06:00
|
|
|
|
|
|
|
|
use Exception;
|
2016-07-10 16:35:03 -05:00
|
|
|
use Illuminate\Auth\AuthenticationException;
|
2014-11-18 22:48:38 -06:00
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
|
|
|
|
2015-02-22 20:47:03 -06:00
|
|
|
class Handler extends ExceptionHandler
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* A list of the exception types that should not be reported.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $dontReport = [
|
2016-07-10 11:35:03 -05:00
|
|
|
\Illuminate\Auth\AuthenticationException::class,
|
2016-05-26 10:00:14 -05:00
|
|
|
\Illuminate\Auth\Access\AuthorizationException::class,
|
|
|
|
|
\Symfony\Component\HttpKernel\Exception\HttpException::class,
|
|
|
|
|
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
|
2016-08-23 15:14:23 +02:00
|
|
|
\Illuminate\Session\TokenMismatchException::class,
|
2016-05-26 10:00:14 -05:00
|
|
|
\Illuminate\Validation\ValidationException::class,
|
2015-02-22 20:47:03 -06:00
|
|
|
];
|
2014-12-02 17:21:16 -06:00
|
|
|
|
2015-02-22 20:47:03 -06:00
|
|
|
/**
|
|
|
|
|
* Report or log an exception.
|
|
|
|
|
*
|
|
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
|
|
|
|
*
|
2016-08-03 10:10:35 -05:00
|
|
|
* @param \Exception $exception
|
2015-02-22 20:47:03 -06:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2016-08-03 10:10:35 -05:00
|
|
|
public function report(Exception $exception)
|
2015-02-22 20:47:03 -06:00
|
|
|
{
|
2016-08-03 10:10:35 -05:00
|
|
|
parent::report($exception);
|
2015-02-22 20:47:03 -06:00
|
|
|
}
|
2014-11-18 22:48:38 -06:00
|
|
|
|
2015-02-22 20:47:03 -06:00
|
|
|
/**
|
|
|
|
|
* Render an exception into an HTTP response.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2016-08-03 10:10:35 -05:00
|
|
|
* @param \Exception $exception
|
2015-02-22 20:47:03 -06:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2016-08-03 10:10:35 -05:00
|
|
|
public function render($request, Exception $exception)
|
2015-02-22 20:47:03 -06:00
|
|
|
{
|
2016-08-03 10:10:35 -05:00
|
|
|
return parent::render($request, $exception);
|
2015-02-22 20:47:03 -06:00
|
|
|
}
|
2016-05-26 10:00:14 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert an authentication exception into an unauthenticated response.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2016-08-03 10:10:35 -05:00
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception
|
2016-05-26 10:00:14 -05:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2016-08-03 10:10:35 -05:00
|
|
|
protected function unauthenticated($request, AuthenticationException $exception)
|
2016-05-26 10:00:14 -05:00
|
|
|
{
|
2016-06-22 08:48:58 -05:00
|
|
|
if ($request->expectsJson()) {
|
2016-06-22 08:46:26 -04:00
|
|
|
return response()->json(['error' => 'Unauthenticated.'], 401);
|
2016-05-26 10:00:14 -05:00
|
|
|
}
|
2016-08-03 10:10:35 -05:00
|
|
|
|
2017-02-17 15:36:28 -02:00
|
|
|
return redirect()->guest(route('login'));
|
2016-05-26 10:00:14 -05:00
|
|
|
}
|
2014-11-18 22:48:38 -06:00
|
|
|
}
|