|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bytesfield\KeyManager\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use Bytesfield\KeyManager\Classes\Errors; |
|
6
|
|
|
use Bytesfield\KeyManager\Traits\ApiResponse; |
|
7
|
|
|
use Illuminate\Auth\AuthenticationException; |
|
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\MethodNotAllowedHttpException; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
13
|
|
|
use Throwable; |
|
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
|
|
|
|