niclasleonbock /
hacktoberfest-status
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Exceptions; |
||
| 4 | |||
| 5 | use Exception; |
||
| 6 | use Illuminate\Auth\AuthenticationException; |
||
| 7 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||
| 8 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
| 9 | |||
| 10 | class Handler extends ExceptionHandler |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * A list of the exception types that should not be reported. |
||
| 14 | * |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | protected $dontReport = [ |
||
| 18 | \Illuminate\Auth\AuthenticationException::class, |
||
| 19 | \Illuminate\Auth\Access\AuthorizationException::class, |
||
| 20 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
| 21 | \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
||
| 22 | \Illuminate\Session\TokenMismatchException::class, |
||
| 23 | \Illuminate\Validation\ValidationException::class, |
||
| 24 | ]; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Report or log an exception. |
||
| 28 | * |
||
| 29 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
||
| 30 | * |
||
| 31 | * @param \Exception $exception |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | public function report(Exception $exception) |
||
| 35 | { |
||
| 36 | if (!app()->environment('local') && app()->bound('sentry') && |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 37 | $this->shouldReport($exception)) { |
||
| 38 | app('sentry')->captureException($exception); |
||
| 39 | } |
||
| 40 | |||
| 41 | parent::report($exception); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Render an exception into an HTTP response. |
||
| 46 | * |
||
| 47 | * @param \Illuminate\Http\Request $request |
||
| 48 | * @param \Exception $exception |
||
| 49 | * @return \Illuminate\Http\Response |
||
| 50 | */ |
||
| 51 | public function render($request, Exception $exception) |
||
| 52 | { |
||
| 53 | if (!app()->environment('local')) { |
||
| 54 | return response()->view('errors.500', [], 500); |
||
| 55 | } |
||
| 56 | |||
| 57 | return parent::render($request, $exception); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Convert an authentication exception into an unauthenticated response. |
||
| 62 | * |
||
| 63 | * @param \Illuminate\Http\Request $request |
||
| 64 | * @param \Illuminate\Auth\AuthenticationException $exception |
||
| 65 | * @return \Illuminate\Http\Response |
||
| 66 | */ |
||
| 67 | protected function unauthenticated($request, AuthenticationException $exception) |
||
| 68 | { |
||
| 69 | if ($request->expectsJson()) { |
||
| 70 | return response()->json(['error' => 'Unauthenticated.'], 401); |
||
| 71 | } |
||
| 72 | |||
| 73 | return redirect()->guest('login'); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |