Corrige ReferenceError safeExtractError e adiciona retries resilientes multi-engine no gerador de imagens
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user