1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bytesfield\KeyManager\Exceptions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
6
|
|
|
use Illuminate\Auth\AuthenticationException; |
7
|
|
|
use Throwable; |
8
|
|
|
use Bytesfield\KeyManager\Traits\ApiResponse; |
9
|
|
|
use Illuminate\Validation\ValidationException; |
10
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
11
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
12
|
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; |
13
|
|
|
use Bytesfield\KeyManager\Classes\Errors; |
14
|
|
|
|
15
|
|
|
class Handler extends ExceptionHandler |
16
|
|
|
{ |
17
|
|
|
use ApiResponse; |
18
|
|
|
/** |
19
|
|
|
* A list of the exception types that are not reported. |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $dontReport = [ |
24
|
|
|
// |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* A list of the inputs that are never flashed for validation exceptions. |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $dontFlash = [ |
33
|
|
|
|
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Handles all throwable exceptions. |
38
|
|
|
* |
39
|
|
|
* @param $request |
40
|
|
|
* @param \Throwable $e |
41
|
|
|
* @return \Illuminate\Support\Facades\Response |
42
|
|
|
*/ |
43
|
|
|
public function render($request, Throwable $e) |
44
|
|
|
{ |
45
|
|
|
if ($e instanceof MethodNotAllowedHttpException) { |
46
|
|
|
return $this->methodNotAllowed(Errors::MESSAGE['METHOD_NOT_FOUND']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($e instanceof NotFoundHttpException) { |
50
|
|
|
return $this->notFound(Errors::MESSAGE['NOT_FOUND']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($e instanceof ModelNotFoundException) { |
54
|
|
|
return $this->notFound(Errors::MESSAGE['NOT_FOUND']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($e instanceof ValidationException) { |
58
|
|
|
return $this->failedValidation(Errors::MESSAGE['VALIDATION_ERROR'], $e->errors()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($e instanceof AuthenticationException) { |
62
|
|
|
return $this->unauthorized($e->getMessage()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $this->buildResponse($e->getMessage(), false, Errors::CODE['SERVER_ERROR']); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|