Fernando Henrique de Jesus ferdnando
unread,Jan 21, 2025, 9:02:09 AMJan 21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to NFePHP
Bom dia, tudo joia?
Alguem ja passou por erros de compatibilidade de navegadores ao obter response da sefaz?
var path = window.location.protocol + '//' + window.location.host;
var notClick = false;
$('#send-sefaz').click(() => {
if (!notClick) {
notClick = true;
$('#send-sefaz').attr('disabled', true);
$('#action').css('display', 'block');
let token = $('#token').val();
let id = $('#id').val();
setTimeout(() => {
$('#acao').html('Gerando XML');
}, 50);
setTimeout(() => {
$('#acao').html('Assinando o arquivo');
}, 800);
setTimeout(() => {
$('#acao').html('Transmitindo para sefaz');
}, 1500);
$.ajax({
type: 'POST',
data: {
id: id,
_token: token
},
url: path + '/nfce/transmitir',
dataType: 'json',
success: function(e) {
console.log(e);
swal("Sucesso", "NFCe emitida, recibo: " + e, "success")
.then(() => {
window.open(path + '/nfce/imprimir/' + id);
location.reload();
});
$('#action').css('display', 'none');
},
error: function(e) {
$('#acao').html('');
$('#action').css('display', 'none');
console.log("Erro completo:", e);
let responseJSON;
try {
// Apenas para o Chrome: verifica a presença de 'e.responseText'
if (navigator.userAgent.includes('Chrome')) {
responseJSON = JSON.parse(e.responseText || "{}");
} else {
responseJSON = e.responseJSON || JSON.parse(e.responseText || "{}");
}
} catch (err) {
console.error("Erro ao processar a resposta:", err);
responseJSON = {};
}
if (e.status === 401 && responseJSON?.protocolo) {
let jsError = JSON.parse(responseJSON.protocolo);
swal("Erro ao transmitir", "[" + jsError.protNFe.infProt.cStat + "] " + jsError.protNFe.infProt.xMotivo, "error");
} else if (e.status === 402) {
swal("Erro ao transmitir", responseJSON.message || "Erro desconhecido", "error");
} else if (e.status === 407) {
swal("Erro ao criar XML", responseJSON.message || "Erro desconhecido", "error");
} else {
try {
let jsError = JSON.parse(responseJSON || "{}");
swal("Erro ao transmitir", "[" + jsError.protNFe.infProt.cStat + "] " + jsError.protNFe.infProt.xMotivo, "error");
} catch {
swal("Erro ao transmitir", responseJSON.message || "Erro desconhecido", "error");
}
}
}
});
}
});
Em certas regeições não consigo capturar o erro correto: no EDGE e no Chorme por exemplo acontece isso.