Handler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 22 4
A report() 0 5 2
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
7
8
class Handler extends ExceptionHandler
9
{
10
    /**
11
     * A list of the exception types that are not reported.
12
     *
13
     * @var array
14
     */
15
    protected $dontReport = [
16
        //
17
    ];
18
19
    /**
20
     * A list of the inputs that are never flashed for validation exceptions.
21
     *
22
     * @var array
23
     */
24
    protected $dontFlash = [
25
        'password',
26
        'password_confirmation',
27
    ];
28
29
    public function report(Exception $exception)
30
    {
31
        if ($exception instanceof BusinessException) return;
32
33
        parent::report($exception);
34
    }
35
36
    /**
37
     * Render an exception into an HTTP response.
38
     *
39
     * @param  \Illuminate\Http\Request  $request
40
     * @param  \Exception  $exception
41
     * @return \Illuminate\Http\Response | \Illuminate\Http\JsonResponse
42
     */
43
    public function render($request, Exception $exception)
44
    {
45
        if ($exception instanceof ServiceException)
46
        {
47
            return response()->json([
48
                'error' => $exception->getUserMessage(),
49
            ], 422);
50
        }
51
52
        if ($exception instanceof BusinessException)
53
        {
54
            return response()->json([
55
                'error' => $exception->getUserMessage(),
56
            ], 422);
57
        }
58
59
        if ($exception instanceof EntityNotFoundException)
60
        {
61
            return response('', 404);
62
        }
63
64
        return parent::render($request, $exception);
65
    }
66
}
67