Conditions | 4 |
Paths | 4 |
Total Lines | 31 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
20 | public static function getDecorated(Manganel $manganel, BadRequest400Exception $exception, $params) |
||
21 | { |
||
22 | // Throw previous exception, |
||
23 | // as it holds more meaningful information |
||
24 | $json = json_encode($params, JSON_PRETTY_PRINT); |
||
25 | |||
26 | $msg = $exception->getMessage(); |
||
27 | |||
28 | $decoded = json_decode($msg); |
||
29 | if(!empty($decoded) && !empty($decoded->error->root_cause[0]->reason)) |
||
30 | { |
||
31 | $msg = $decoded->error->root_cause[0]->reason; |
||
32 | } |
||
33 | |||
34 | $prevMsg = ''; |
||
35 | $previous = $exception->getPrevious(); |
||
36 | if(!empty($previous)) |
||
37 | { |
||
38 | $prevMsg = '(' . $previous->getMessage() . ')'; |
||
39 | } |
||
40 | |||
41 | $params = [ |
||
42 | $msg . ' ' . $prevMsg, |
||
43 | $manganel->indexId, |
||
44 | $json |
||
45 | ]; |
||
46 | |||
47 | |||
48 | $message = vsprintf("Exception %s while querying `%s`: \n%s\n", $params); |
||
49 | return new BadRequest400Exception($message, 400, $exception); |
||
50 | } |
||
51 | } |