if (!empty($arr2["errors"]) && is_array($arr2["errors"])) {
$errorDescriptions = [];
foreach ($arr2["errors"] as $err) {
- if (!empty($err["error_description"])) {
- $errorDescriptions[] = $err["error_description"];
+ $errorParts = [];
+
+ // Обрабатываем error_json - все элементы массива
+ if (!empty($err["error_json"]) && is_array($err["error_json"])) {
+ foreach ($err["error_json"] as $errorJson) {
+ if (!empty($errorJson["field"]) && !empty($errorJson["error"])) {
+ $errorParts[] = 'Значение поля ' . $errorJson["field"] . ' с ошибкой: ' . $errorJson["error"];
+ } elseif (!empty($errorJson["error"])) {
+ $errorParts[] = $errorJson["error"];
+ }
+ }
+ }
+
+ // Используем error_description как fallback, если нет error_json
+ if (empty($errorParts) && !empty($err["error_description"])) {
+ $errorParts[] = $err["error_description"];
+ }
+
+ // Добавляем error, если есть и еще ничего не добавлено
+ if (empty($errorParts) && !empty($err["error"])) {
+ $errorParts[] = $err["error"];
+ }
+
+ // Объединяем части ошибки для текущего элемента
+ if (!empty($errorParts)) {
+ $errorDescriptions[] = implode('; ', $errorParts);
}
}
$errorText = implode('; ', $errorDescriptions);