Handler::report()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Database\Eloquent\ModelNotFoundException;
7
use Response;
8
use Symfony\Component\HttpKernel\Exception\HttpException;
9
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
11
12
class Handler extends ExceptionHandler
13
{
14
    /**
15
     * A list of the exception types that should not be reported.
16
     *
17
     * @var array
18
     */
19
    protected $dontReport = [
20
        HttpException::class,
21
        ModelNotFoundException::class,
22
    ];
23
24
    /**
25
     * Report or log an exception.
26
     *
27
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
28
     *
29
     * @param  \Exception  $e
30
     * @return void
31
     */
32
    public function report(Exception $e)
33
    {
34
        return parent::report($e);
35
    }
36
37
    /**
38
     * Render an exception into an HTTP response.
39
     *
40
     * @param  \Illuminate\Http\Request  $request
41
     * @param  \Exception  $e
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function render($request, Exception $e)
45
    {
46
        if ($e instanceof ModelNotFoundException) {
47
            $e = new NotFoundHttpException($e->getMessage(), $e);
48
        } elseif($e instanceof HttpException && \App::isLocal() === false) {
49
            Response::json(['result' => false, 'message' => $e->getMessage()])
50
                ->setStatusCode($e->getStatusCode())
51
                ->send();
52
53
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method render() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
54
        }
55
56
        return parent::render($request, $e);
57
    }
58
}
59