Conditions | 4 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 0 | Features | 5 |
1 | <?php |
||
39 | public function handle($exception, $code = 0, $status = 500, $headers = [], $options = 0) |
||
40 | { |
||
41 | if (is_string($exception)) { |
||
42 | $message = $exception; |
||
43 | } // This is a generic, non-supported exception so we'll just treat it as so. |
||
44 | elseif ($exception instanceof Exception || $exception instanceof RuntimeException) { |
||
45 | $code = $exception->getCode(); |
||
46 | $message = $exception->getMessage(); |
||
47 | } // if not Exception or RuntimeException or a string then throw and API exception |
||
48 | else { |
||
49 | throw new ApiException('Argument 1 passed Vinelab\Api\ErrorHandler::handle() must be an instance of |
||
50 | Exception or RuntimeException or a string, '.get_class($exception).' is given.'); |
||
51 | } |
||
52 | $response = [ |
||
53 | 'status' => $status, |
||
54 | 'error' => compact('message', 'code'), |
||
55 | ]; |
||
56 | |||
57 | return $this->responder->respond($response, $status, $headers, $options); |
||
58 | } |
||
59 | } |
||
60 |