|
|
@@ -455,10 +455,36 @@ class FattureInCloudClient
|
|
455
|
455
|
return $response->json() ?? [];
|
|
456
|
456
|
}
|
|
457
|
457
|
|
|
458
|
|
- $message = data_get($response->json(), 'error.message')
|
|
459
|
|
- ?: data_get($response->json(), 'message')
|
|
|
458
|
+ $json = $response->json();
|
|
|
459
|
+ $message = data_get($json, 'error.message')
|
|
|
460
|
+ ?: data_get($json, 'message')
|
|
460
|
461
|
?: 'Fatture in Cloud ha risposto con errore '.$response->status().'.';
|
|
|
462
|
+ $details = $this->validationDetails(data_get($json, 'error.validation_result'));
|
|
|
463
|
+ if ($details !== '') {
|
|
|
464
|
+ $message .= ' '.$details;
|
|
|
465
|
+ }
|
|
461
|
466
|
|
|
462
|
467
|
throw new RuntimeException((string) $message);
|
|
463
|
468
|
}
|
|
|
469
|
+
|
|
|
470
|
+ private function validationDetails(mixed $result): string
|
|
|
471
|
+ {
|
|
|
472
|
+ if (is_string($result)) {
|
|
|
473
|
+ return trim($result);
|
|
|
474
|
+ }
|
|
|
475
|
+ if (! is_array($result)) {
|
|
|
476
|
+ return '';
|
|
|
477
|
+ }
|
|
|
478
|
+
|
|
|
479
|
+ $parts = [];
|
|
|
480
|
+ foreach ($result as $key => $value) {
|
|
|
481
|
+ $text = $this->validationDetails($value);
|
|
|
482
|
+ if ($text === '') {
|
|
|
483
|
+ continue;
|
|
|
484
|
+ }
|
|
|
485
|
+ $parts[] = is_string($key) ? $key.': '.$text : $text;
|
|
|
486
|
+ }
|
|
|
487
|
+
|
|
|
488
|
+ return implode(' ', $parts);
|
|
|
489
|
+ }
|
|
464
|
490
|
}
|