1 | <?php |
||
14 | trait ErrorContainerTrait |
||
15 | { |
||
16 | |||
17 | /** @var \Exception[] */ |
||
18 | protected $errors = []; |
||
19 | |||
20 | 42 | public function addError(\Exception $exception) |
|
26 | |||
27 | 90 | public function hasErrors() |
|
31 | |||
32 | 1 | public function getErrors() |
|
36 | |||
37 | 1 | public function mergeErrors(ErrorContainerInterface $errorContainer) |
|
47 | |||
48 | 42 | public function getErrorsArray($inGraphQLStyle = true) |
|
49 | { |
||
50 | 42 | $errors = []; |
|
51 | |||
52 | 42 | foreach ($this->errors as $error) { |
|
53 | 42 | if ($inGraphQLStyle) { |
|
54 | 21 | if ($error instanceof DatableExceptionInterface) { |
|
55 | 1 | $errors[] = array_merge( |
|
56 | 1 | ['message' => $error->getMessage()], |
|
57 | 1 | $error->getData() ?: [], |
|
58 | 1 | $error->getCode() ? ['code' => $error->getCode()] : [] |
|
59 | 1 | ); |
|
60 | 21 | } elseif ($error instanceof LocationableExceptionInterface) { |
|
61 | 18 | $errors[] = array_merge( |
|
62 | 18 | ['message' => $error->getMessage()], |
|
63 | 18 | $error->getLocation() ? ['locations' => [$error->getLocation()->toArray()]] : [], |
|
64 | 18 | $error->getCode() ? ['code' => $error->getCode()] : [] |
|
65 | 18 | ); |
|
66 | 18 | } else { |
|
67 | 4 | $errors[] = array_merge( |
|
68 | 4 | ['message' => $error->getMessage()], |
|
69 | 4 | $error->getCode() ? ['code' => $error->getCode()] : [] |
|
70 | 4 | ); |
|
71 | } |
||
72 | 21 | } else { |
|
73 | 21 | $errors[] = $error->getMessage(); |
|
74 | } |
||
75 | 42 | } |
|
76 | |||
77 | 42 | return $errors; |
|
78 | } |
||
79 | |||
80 | 115 | public function clearErrors() |
|
86 | |||
87 | } |