|
15 | 15 | use Shopware\Core\Framework\HttpException; |
16 | 16 | use Shopware\Core\Framework\Log\Package; |
17 | 17 | use Shopware\Core\Framework\ShopwareHttpException; |
| 18 | +use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException; |
18 | 19 | use Shopware\PayPalSDK\Contract\Gateway\GatewayInterface; |
19 | 20 | use Swag\PayPal\Pos\Api\Exception\PosException; |
20 | 21 | use Swag\PayPal\Pos\Client\AbstractClient as PosAbstractClient; |
@@ -149,21 +150,27 @@ protected function getBacktrace(): array |
149 | 150 | */ |
150 | 151 | private function exceptionToContext(\Throwable $exception): array |
151 | 152 | { |
152 | | - $context = [ |
153 | | - 'message' => $exception->getMessage(), |
154 | | - 'class' => $this->traceToClassString($exception->getTrace()[0]), |
155 | | - 'file' => $exception->getFile(), |
156 | | - 'line' => $exception->getLine(), |
157 | | - ]; |
| 153 | + $context = ['message' => $exception->getMessage()]; |
158 | 154 |
|
159 | 155 | if ($exception instanceof ShopwareHttpException) { |
160 | 156 | $context['parameters'] = $exception->getParameters(); |
161 | 157 | } |
162 | 158 |
|
| 159 | + if ($exception instanceof ConstraintViolationException) { |
| 160 | + foreach ($exception->getViolations() as $violation) { |
| 161 | + $context['parameters']['violations'][] = (string) $violation; |
| 162 | + } |
| 163 | + } |
| 164 | + |
163 | 165 | if ($exception instanceof HttpException || $exception instanceof PosException) { |
164 | 166 | $context['errorCode'] = $exception->getErrorCode(); |
165 | 167 | } |
166 | 168 |
|
| 169 | + // Order class, file and line at the end to make the exception & the most important information more readable in logs |
| 170 | + $context['class'] = $this->traceToClassString($exception->getTrace()[0]); |
| 171 | + $context['file'] = $exception->getFile(); |
| 172 | + $context['line'] = $exception->getLine(); |
| 173 | + |
167 | 174 | if ($exception->getPrevious()) { |
168 | 175 | $context['previous'] = $this->exceptionToContext($exception->getPrevious()); |
169 | 176 | } |
|
0 commit comments