feat(certidao): adicionar tratamento de erro para certidão já existente e decodificação de erros do backend
All checks were successful
Dev Build & Deploy Portal / build-deploy (push) Successful in 3m15s
All checks were successful
Dev Build & Deploy Portal / build-deploy (push) Successful in 3m15s
This commit is contained in:
parent
c6adda9bfb
commit
7fd1460bca
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user