debug(template): expose Meta error subcode/details, add canal meta
- WhatsAppService::makeRequest: include error_subcode and error_data.details in the thrown exception message to surface the real reason for #100 errors - chat_send_message: log template name/lang/params before sending; pass canal+operator_id meta so outgoing templates are tagged correctly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f60df038d8
commit
a8380ddc81
@@ -35,7 +35,10 @@ try {
|
|||||||
$wa = new WhatsAppService('turnero');
|
$wa = new WhatsAppService('turnero');
|
||||||
|
|
||||||
if ($type === 'template') {
|
if ($type === 'template') {
|
||||||
$response = $wa->sendTemplateMessage($user['phone_number'], $template, $lang, $params);
|
error_log("chat_send_message template: name={$template} lang={$lang} params=" . json_encode($params));
|
||||||
|
$meta = ['canal' => 'turnero'];
|
||||||
|
if ($operatorId) $meta['operator_id'] = $operatorId;
|
||||||
|
$response = $wa->sendTemplateMessage($user['phone_number'], $template, $lang, $params, [], null, $meta);
|
||||||
} else {
|
} else {
|
||||||
$extra = ['canal' => 'turnero'];
|
$extra = ['canal' => 'turnero'];
|
||||||
if ($operatorId) $extra['operator_id'] = $operatorId;
|
if ($operatorId) $extra['operator_id'] = $operatorId;
|
||||||
|
|||||||
@@ -854,16 +854,17 @@ class WhatsAppService
|
|||||||
$decoded = json_decode($response, true);
|
$decoded = json_decode($response, true);
|
||||||
|
|
||||||
if ($httpCode >= 400) {
|
if ($httpCode >= 400) {
|
||||||
$errorMsg = isset($decoded['error']['message']) ? $decoded['error']['message'] : 'Error desconocido';
|
$err = $decoded['error'] ?? [];
|
||||||
|
$errorMsg = $err['message'] ?? 'Error desconocido';
|
||||||
// Debug detallado
|
$details = $err['error_data']['details'] ?? ($err['error_data']['description'] ?? null);
|
||||||
error_log("WhatsApp API Error Details:");
|
$subcode = $err['error_subcode'] ?? null;
|
||||||
error_log("- URL: " . $url);
|
|
||||||
error_log("- HTTP Code: " . $httpCode);
|
error_log("WhatsApp API Error: HTTP={$httpCode} code={$err['code']} sub={$subcode} msg={$errorMsg} details={$details} body=" . substr($response, 0, 400));
|
||||||
error_log("- Response: " . $response);
|
|
||||||
error_log("- Token (first 20 chars): " . substr($this->token, 0, 20) . "...");
|
$full = $errorMsg;
|
||||||
|
if ($subcode) $full .= " (sub:{$subcode})";
|
||||||
throw new Exception("Error de WhatsApp API: " . $errorMsg);
|
if ($details) $full .= " — {$details}";
|
||||||
|
throw new Exception("Error de WhatsApp API: " . $full);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $decoded;
|
return $decoded;
|
||||||
|
|||||||
Reference in New Issue
Block a user