developer #4

Open
gabrielb wants to merge 20 commits from developer into main
Showing only changes of commit 7fd1460bca - Show all commits

View File

@ -74,6 +74,22 @@ function extrairErro(e) {
return e?.data?.description ?? e?.data?.data?.description ?? e?.statusMessage ?? null return e?.data?.description ?? e?.data?.data?.description ?? e?.statusMessage ?? null
} }
const COD_CERTIDAO_VALIDA_JA_EXISTE = '214'
// Respostas de erro do endpoint de emissão chegam como ArrayBuffer (responseType
// é 'arrayBuffer' para o PDF). Decodifica o envelope JSON para ler o StandardError.
function lerEnvelopeErro(e) {
let body = e?.data
if (body instanceof ArrayBuffer) {
try {
body = JSON.parse(new TextDecoder().decode(body))
} catch {
return null
}
}
return body ?? null
}
async function carregarModelos() { async function carregarModelos() {
if (!docValido.value) { if (!docValido.value) {
resetModelos() resetModelos()
@ -160,7 +176,8 @@ async function emitir() {
return return
} }
} catch { } catch {
// endpoint indisponível prossegue com emissão normalmente // Pré-checagem indisponível a emissão é bloqueada de forma autoritativa
// pelo backend, que devolve o erro CERTIDAO_VALIDA_JA_EXISTE tratado abaixo.
} }
try { try {
@ -190,7 +207,14 @@ async function emitir() {
etapa.value = 'sucesso' etapa.value = 'sucesso'
} }
} catch (e) { } catch (e) {
mensagemErro.value = extrairErro(e) ?? 'Erro ao gerar o PDF. Tente novamente.' const erroBackend = lerEnvelopeErro(e)?.data
const existente = erroBackend?.response
if (erroBackend?.internalCode === COD_CERTIDAO_VALIDA_JA_EXISTE && existente?.id != null) {
certidaoExistente.value = existente
etapa.value = 'certidaoExistente'
return
}
mensagemErro.value = erroBackend?.description ?? extrairErro(e) ?? 'Erro ao gerar o PDF. Tente novamente.'
} finally { } finally {
carregandoEmissao.value = false carregandoEmissao.value = false
} }