1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SoliDry\Exceptions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\JsonResponse; |
6
|
|
|
use SoliDry\Extension\JSONApiInterface; |
7
|
|
|
use SoliDry\Helpers\Json; |
8
|
|
|
|
9
|
|
|
class BaseException extends \Exception |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* BaseException constructor. |
14
|
|
|
* |
15
|
|
|
* @param $message |
16
|
|
|
* @param int $code |
17
|
|
|
*/ |
18
|
|
|
public function __construct($message, $code = 0) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($message, $code); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function __toString() |
24
|
|
|
{ |
25
|
|
|
parent::__toString(); |
26
|
|
|
return (new Json)->getErrors([ |
27
|
|
|
'code' => $this->getCode(), |
28
|
|
|
'message' => $this->getMessage(), |
29
|
|
|
'file' => $this->getFile(), |
30
|
|
|
'line' => $this->getLine(), |
31
|
|
|
]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Render the exception into an HTTP response. |
36
|
|
|
* |
37
|
|
|
* @param \Illuminate\Http\Request $request |
38
|
|
|
* @return JsonResponse |
39
|
|
|
*/ |
40
|
|
|
public function render($request) : JsonResponse |
41
|
|
|
{ |
42
|
|
|
return response()->json( |
43
|
|
|
[ |
44
|
|
|
JSONApiInterface::CONTENT_ERRORS => [ |
45
|
|
|
[ |
46
|
|
|
'code' => $this->getCode(), |
47
|
|
|
'message' => $this->getMessage(), |
48
|
|
|
'file' => $this->getFile(), |
49
|
|
|
'line' => $this->getLine(), |
50
|
|
|
'uri' => $request->getUri(), |
51
|
|
|
'meta' => $this->getTraceAsString(), |
52
|
|
|
], |
53
|
|
|
] |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|