Handler.php 2.17 KB
Newer Older
Dominik Hebeler's avatar
Dominik Hebeler committed
1
2
3
4
5
<?php

namespace App\Exceptions;

use Exception;
6
use Illuminate\Auth\AuthenticationException;
Dominik Hebeler's avatar
Dominik Hebeler committed
7
8
9
10
11
12
13
14
15
16
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
17
18
19
20
21
22
        \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,
Dominik Hebeler's avatar
Dominik Hebeler committed
23
24
25
26
27
28
29
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
30
     * @param  \Exception  $exception
Dominik Hebeler's avatar
Dominik Hebeler committed
31
32
     * @return void
     */
33
    public function report(Exception $exception)
Dominik Hebeler's avatar
Dominik Hebeler committed
34
    {
35
        parent::report($exception);
Dominik Hebeler's avatar
Dominik Hebeler committed
36
37
38
39
40
41
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
42
     * @param  \Exception  $exception
Dominik Hebeler's avatar
Dominik Hebeler committed
43
44
     * @return \Illuminate\Http\Response
     */
45
    public function render($request, Exception $exception)
Dominik Hebeler's avatar
Dominik Hebeler committed
46
    {
47
48
49
50
51
        if ($request->is('*/meta/meta.ger3*')) {
            $registry = \Prometheus\CollectorRegistry::getDefault();
            $histogram = $registry->getOrRegisterHistogram('metager', 'result_histogram', 'counts total number of returned results', [], [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]);
            $histogram->observe(0);
        }
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        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');
Dominik Hebeler's avatar
Dominik Hebeler committed
69
70
    }
}