Handler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 22
dl 0
loc 59
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 3 1
A render() 0 24 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Exceptions;
6
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Illuminate\Http\Response;
10
use Illuminate\Validation\ValidationException;
11
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
12
use Minepic\Misc\SplashMessage;
13
use Symfony\Component\HttpKernel\Exception\HttpException;
14
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15
16
class Handler extends ExceptionHandler
17
{
18
    /**
19
     * A list of the exception types that should not be reported.
20
     *
21
     * @var array
22
     */
23
    protected $dontReport = [
24
        AuthorizationException::class,
25
        HttpException::class,
26
        ModelNotFoundException::class,
27
        ValidationException::class,
28
    ];
29
30
    /**
31
     * Report or log an exception.
32
     *
33
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
34
     *
35
     * @throws \Exception
36
     */
37
    public function report(\Throwable $e)
38
    {
39
        parent::report($e);
40
    }
41
42
    /**
43
     * Render an exception into an HTTP response.
44
     *
45
     * @param \Illuminate\Http\Request $request
46
     *
47
     * @throws \Throwable
48
     *
49
     * @return mixed
50
     */
51
    public function render($request, \Throwable $e)
52
    {
53
        if ($e instanceof NotFoundHttpException) {
54
            return response(
55
                view('public.template.header', [
56
                    'title' => 'Ooops 404! - Minepic',
57
                    'description' => 'Error content not found',
58
                    'keywords' => '404, error',
59
                    'randomMessage' => SplashMessage::get404(),
60
                ]).
61
                view('public.errors.404').
62
                view('public.template.footer'),
63
                Response::HTTP_NOT_FOUND
64
            );
65
        }
66
67
        if ($e instanceof NotFoundHttpJsonException) {
68
            return response(
69
                json_encode(['ok' => false, $e->getMessage()], JSON_THROW_ON_ERROR),
70
                Response::HTTP_NOT_FOUND
71
            );
72
        }
73
74
        return parent::render($request, $e);
75
    }
76
}
77