Files
baodev0andClaude Sonnet 5.5 62596d9063 feat(vm): hoàn tiền khi cấp VM lỗi, theo dõi job queue, uuid dịch vụ cho ticket, chuẩn hoá RAM addon
- VmProvisionException/VmProvisionRefund xử lý lỗi cấp phát VM
- QueueJobInspector + QueueMonitorController xem chi tiết job
- Thêm service uuid cho ticket, thời lượng cho activity_logs
- Migration chuẩn hoá RAM addon sang MB, trạng thái deleting cho snapshot

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 11:54:05 +07:00

48 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\VirtualMachine;
class VmVcenterErrorTranslator
{
private const MESSAGES = [
'NOT_FOUND' => 'Không tìm thấy template hoặc tài nguyên trên vCenter. Vui lòng liên hệ hỗ trợ.',
'RESOURCE_INACCESSIBLE' => 'Tài nguyên vCenter không khả dụng. Vui lòng thử lại sau hoặc liên hệ hỗ trợ.',
'INVALID_ARGUMENT' => 'Thông tin cấu hình máy chủ không hợp lệ. Vui lòng liên hệ hỗ trợ.',
'UNABLE_TO_ALLOCATE_RESOURCE' => 'Không đủ tài nguyên để khởi tạo máy chủ. Vui lòng liên hệ hỗ trợ.',
'TIMED_OUT' => 'Yêu cầu khởi tạo máy chủ hết thời gian chờ. Vui lòng thử lại sau.',
];
public function detail(array $result): string
{
$data = $result['data'] ?? [];
$messages = is_array($data) ? collect($data['messages'] ?? [])->pluck('default_message')->filter() : collect();
if ($messages->isNotEmpty()) {
return ($data['error_type'] ?? 'vCenter') . ': ' . $messages->implode(' | ');
}
return is_string($data) ? $data : (string) json_encode($data, JSON_UNESCAPED_UNICODE);
}
public function translate(array $result, ?string $serverName = null): string
{
$data = $result['data'] ?? [];
$errorType = is_array($data) ? ($data['error_type'] ?? '') : '';
if ($errorType === 'ALREADY_EXISTS') {
return "Tên máy chủ \"{$serverName}\" đã tồn tại trong hệ thống. "
. 'Vui lòng liên hệ hỗ trợ để được xử lý hoặc chọn tên máy chủ khác.';
}
if ($errorType && isset(self::MESSAGES[$errorType])) {
return self::MESSAGES[$errorType];
}
// Avoid leaking raw JSON to customers
return 'Không thể khởi tạo máy chủ ảo lúc này. Chúng tôi đã ghi nhận và sẽ xử lý trong thời gian sớm nhất. '
. 'Vui lòng liên hệ hỗ trợ nếu cần.';
}
}