Handler::render()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.2
cc 4
eloc 6
nc 3
nop 2
crap 4
1
<?php
2
3
namespace App\Exceptions;
4
5
use Chrisbjr\ApiGuard\Builders\ApiResponseBuilder;
6
use Exception;
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
10
use Illuminate\Validation\ValidationException;
11
use Symfony\Component\HttpKernel\Exception\HttpException;
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
14
class Handler extends ExceptionHandler
15
{
16
    /**
17
     * A list of the exception types that should not be reported.
18
     *
19
     * @var array
20
     */
21
    protected $dontReport = [
22
        AuthorizationException::class,
23
        HttpException::class,
24
        ModelNotFoundException::class,
25
        ValidationException::class,
26
    ];
27
28
    /**
29
     * Report or log an exception.
30
     *
31
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
32
     *
33
     * @param \Exception $e
34
     *
35
     * @return void
36
     */
37 4
    public function report(Exception $e)
38
    {
39 4
        parent::report($e);
40 4
    }
41
42
    /**
43
     * Render an exception into an HTTP response.
44
     *
45
     * @param \Illuminate\Http\Request $request
46
     * @param \Exception               $e
47
     *
48
     * @return \Illuminate\Http\Response
49
     */
50 4
    public function render($request, Exception $e)
51
    {
52 4
        $response = ApiResponseBuilder::build();
53
54 4
        if ($request->json()) {
55 4
            if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException) {
56 2
                return $response->errorNotFound();
57
            }
58 2
        }
59
60 2
        return parent::render($request, $e);
61
    }
62
}
63