Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions erros.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const listaDeErros = [
{ codigo: 'LIQ00001', palavraChave: 'não encontrado' },
{ codigo: 'LIQ00002', palavraChave: 'não foi definida' },
{ codigo: 'LIQ00003', palavraChave: 'inesperado' },
];
163 changes: 155 additions & 8 deletions liquido.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { AcessoMetodo, Chamada, FuncaoConstruto, Variavel } from '@designliquido/delegua/construtos';
import { Expressao, FuncaoDeclaracao } from '@designliquido/delegua/declaracoes';
import { DeleguaFuncao, ObjetoDeleguaClasse } from '@designliquido/delegua/interpretador/estruturas';
import { InterpretadorInterface, ResultadoParcialInterpretadorInterface, RetornoInterpretadorInterface, SimboloInterface, VariavelInterface } from '@designliquido/delegua/interfaces';
import { ErroInterpretadorInterface, InterpretadorInterface, ResultadoParcialInterpretadorInterface, RetornoInterpretadorInterface, SimboloInterface, VariavelInterface } from '@designliquido/delegua/interfaces';
import { InformacaoElementoSintatico } from '@designliquido/delegua/informacao-elemento-sintatico';
import { Lexador, Simbolo } from '@designliquido/delegua/lexador';

Expand All @@ -24,6 +24,7 @@
import { Requisicao } from './infraestrutura/requisicao';
import { InterpretadorLiquido } from './infraestrutura/interpretador-liquido';
import { RetornoQuebra } from '@designliquido/delegua/quebras';
import { listaDeErros } from './erros';

/**
* O núcleo do framework.
Expand Down Expand Up @@ -397,23 +398,169 @@
}
}

private logicaComumErrosInterpretacao(retornoInterpretador: RetornoInterpretadorInterface): {
private classificarErro(erro: ErroInterpretadorInterface): string {
const textoErro = (erro.mensagem || erro.erroInterno?.message || '').toLowerCase();

Check warning on line 402 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 402 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 402 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 402 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 402 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 402 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

for (const item of listaDeErros) {
if (textoErro.includes(item.palavraChave)) {
return item.codigo;

Check warning on line 406 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 407 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

return 'LIQ99999';
}

private logicaComumErrosInterpretacao(
retornoInterpretador: RetornoInterpretadorInterface
): {
corpoRetorno?: any;
statusHttp?: number;
redirecionamento?: string;
} {
let corpoRetorno = '';
const listaErros: string[] = [];

for (const erro of retornoInterpretador.erros) {
const tipoErro = this.classificarErro(erro);

if (erro.erroInterno) {
const erroInternoTipado: { message: string; stack: string } = erro.erroInterno;
corpoRetorno += erroInternoTipado.message;
corpoRetorno += erroInternoTipado.stack;
const erroInternoTipado: {
Comment thread
leonelsanchesdasilva marked this conversation as resolved.
message: string;
pilha: string;
} = erro.erroInterno;

listaErros.push(
`
Código: ${tipoErro}\n
Mensagem: ${erroInternoTipado.message}\n
Pilha: ${erroInternoTipado.pilha}
`
);

Check warning on line 437 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else {
corpoRetorno += `[Linha ${erro.linha}]: ${erro.mensagem}`;
listaErros.push(
`${tipoErro} - [Linha ${erro.linha}]: ${erro.mensagem}`
);
}

Check warning on line 442 in liquido.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

return { corpoRetorno: corpoRetorno, statusHttp: 500 };
let corpoFinal: any;

if (this.centroConfiguracoes.liquido.arquetipo === 'mvc') {
const itensLista = listaErros
.map(erro => `<li><pre>${erro}</pre></li>`)
.join('');

corpoFinal = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Erro de Execução - Líquido</title>
<style>
:root {
--fundo: #f4f6f8;
--texto: #333;
--vermelho-topo: #dc3545;
--branco: #ffffff;
--borda: #e1e4e8;
--fundo-codigo: #2d2d2d;
--texto-codigo: #f8f8f2;
}

body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--fundo);
color: var(--texto);
margin: 0;
padding: 0;
line-height: 1.6;
}

.cabecalho-erro {
background-color: var(--vermelho-topo);
color: var(--branco);
padding: 40px 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.container {
max-width: 1000px;
margin: 0 auto;
}

h1 {
margin: 0;
font-size: 2.2rem;
font-weight: 600;
}

h2 {
color: var(--vermelho-topo);
border-bottom: 2px solid #ffcccc;
padding-bottom: 10px;
margin-top: 40px;
font-size: 1.5rem;
}

.conteudo {
padding: 20px;
}

ul.stack-trace {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 15px;
}

ul.stack-trace li {
background: var(--branco);
border: 1px solid var(--borda);
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
overflow-x: auto;
}

pre {
background-color: var(--fundo-codigo);
color: var(--texto-codigo);
padding: 15px;
border-radius: 6px;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 14px;
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<div class="cabecalho-erro">
<div class="container">
<h1>Ocorreu um erro</h1>
</div>
</div>

<div class="container conteudo">
<h2>Pilha de Execução</h2>
<ul class="stack-trace">${itensLista}</ul>
</div>
</body>
</html>
`;
}

if (this.centroConfiguracoes.liquido.arquetipo === 'rest') {
corpoFinal = {
mensagem: 'Ocorreu um erro interno na aplicação.',
detalhes: listaErros
};
}

return { corpoRetorno: corpoFinal, statusHttp: 500 };
}

/**
Expand Down
24 changes: 24 additions & 0 deletions testes/liquido.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,29 @@ describe('Liquido', () => {
expect(resultadoLimpo[0]).toEqual({ id: 1 });
expect(resultadoLimpo[0]).not.toHaveProperty('endereco');
});

it('[MVC] Deve retornar tela de erro', () => {
(liquido as any).centroConfiguracoes = {
liquido: { arquetipo: 'mvc' }
}

const erroFalso = {
erros: [
{
linha: 1,
mensagem: "Aconteceu um erro..."
}
]
};

const resultado = (liquido as any).logicaComumErrosInterpretacao(
erroFalso
);

expect(resultado.statusHttp).toBe(500);
expect(resultado.corpoRetorno).toContain(
'Erro de Execução - Líquido'
);
});
});
});
Loading