const res = await fetch('https://api.waspytech.com/api/v2/messages', {
method: 'POST',
headers: {
'Authorization': 'Bearer wspy_...',
'Content-Type': 'application/json'
},
body: JSON.stringify({ ... })
});
if (!res.ok) {
const { error, meta } = await res.json();
switch (error.code) {
case 'RATE_LIMITED':
// Esperar y reintentar
break;
case 'SERVICE_WINDOW_EXPIRED':
// Enviar un template en vez de texto libre
break;
case 'CONTACT_ALREADY_EXISTS':
// El contacto ya existe, usar el existente
break;
default:
console.error(`Error ${error.code}: ${error.message} (${meta.requestId})`);
}
}