Corrige ReferenceError safeExtractError e adiciona retries resilientes multi-engine no gerador de imagens

This commit is contained in:
2026-08-31 14:24:36 +00:00
parent a08c741a4f
commit e994ac1c40
2 changed files with 53 additions and 19 deletions
+20
View File
@@ -11,6 +11,26 @@ function escapeHtml(text) {
.replace(/'/g, "'");
}
// Helper global para extração segura de erros de resposta HTTP no frontend
async function safeExtractError(resp, defaultMsg = 'Erro na operação') {
if (!resp) return defaultMsg;
try {
const text = await resp.text();
try {
const json = JSON.parse(text);
return json.error || defaultMsg;
} catch (e) {
if (resp.status === 502 || text.includes('Bad Gateway')) {
return 'O servidor está temporariamente ocupado processando a requisição. Por favor, tente novamente em instantes.';
}
return text.slice(0, 160) || defaultMsg;
}
} catch (e) {
return defaultMsg;
}
}
// Função global para exibir notificações elegantes estilo Toast
function showToast(message, type = 'info') {
let container = document.getElementById('toast-container');