sfelix-martins /
json-exception-handler
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SMartins\JsonHandler; |
||
| 4 | |||
| 5 | use Cielo\API30\Ecommerce\Request\CieloRequestException; |
||
| 6 | |||
| 7 | trait CieloRequestHandler |
||
| 8 | { |
||
| 9 | public function cieloRequestException(CieloRequestException $e) |
||
| 10 | { |
||
| 11 | $errors = []; |
||
| 12 | $code = $e->getCode(); |
||
| 13 | do { |
||
| 14 | $cieloError = $e->getCieloError(); |
||
| 15 | $error = [ |
||
| 16 | 'status' => $e->getCode(), |
||
| 17 | 'code' => $this->getCode('cielo').$cieloError->getCode(), |
||
| 18 | 'source' => ['pointer' => $e->getFile().':'.$e->getLine()], |
||
| 19 | 'title' => $e->getMessage(), |
||
| 20 | 'detail' => $cieloError->getMessage(), |
||
| 21 | ]; |
||
| 22 | if (! in_array($error, $errors)) { |
||
| 23 | array_push($errors, $error); |
||
| 24 | } |
||
| 25 | $e = $e->getPrevious(); |
||
| 26 | } while (method_exists($e, 'getPrevious')); |
||
| 27 | |||
| 28 | $this->jsonApiResponse->setStatus($code); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 29 | $this->jsonApiResponse->setErrors($errors); |
||
| 30 | } |
||
| 31 | } |
||
| 32 |