Adiciona detalhes do erro na api de musicas e historias

This commit is contained in:
2026-06-05 16:31:11 +00:00
parent 4c356794a2
commit e9ada11ce7
+12 -4
View File
@@ -1316,6 +1316,10 @@ ${idadeInstrucao}
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ contents: [{ parts: [{ text: systemInstruction }] }] }) body: JSON.stringify({ contents: [{ parts: [{ text: systemInstruction }] }] })
}); });
if (!response.ok) {
const txt = await response.text();
throw new Error(`Gemini Error: ${txt}`);
}
const data = await response.json(); const data = await response.json();
musicaText = data.candidates?.[0]?.content?.parts?.[0]?.text || ''; musicaText = data.candidates?.[0]?.content?.parts?.[0]?.text || '';
} }
@@ -1323,7 +1327,7 @@ ${idadeInstrucao}
// Limpeza // Limpeza
musicaText = musicaText.replace(/<think>[\s\S]*?<\/think>/gi, '').trim(); musicaText = musicaText.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
if (!musicaText) throw new Error('Falha ao gerar música'); if (!musicaText) throw new Error('Falha ao gerar música (texto vazio)');
const dbRes = await dbPool.query( const dbRes = await dbPool.query(
`INSERT INTO escola.musicas (usuario_id, faixa_etaria, estrofes, ritmo, tema, musica) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id`, `INSERT INTO escola.musicas (usuario_id, faixa_etaria, estrofes, ritmo, tema, musica) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id`,
@@ -1333,7 +1337,7 @@ ${idadeInstrucao}
res.json({ id: dbRes.rows[0].id, musica: musicaText }); res.json({ id: dbRes.rows[0].id, musica: musicaText });
} catch (err) { } catch (err) {
console.error('Erro Música:', err); console.error('Erro Música:', err);
res.status(500).json({ error: 'Erro ao gerar música.' }); res.status(500).json({ error: 'Erro ao gerar música: ' + err.message });
} }
}); });
@@ -1399,13 +1403,17 @@ ${idadeInstrucao}
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ contents: [{ parts: [{ text: systemInstruction }] }] }) body: JSON.stringify({ contents: [{ parts: [{ text: systemInstruction }] }] })
}); });
if (!response.ok) {
const txt = await response.text();
throw new Error(`Gemini Error: ${txt}`);
}
const data = await response.json(); const data = await response.json();
historiaText = data.candidates?.[0]?.content?.parts?.[0]?.text || ''; historiaText = data.candidates?.[0]?.content?.parts?.[0]?.text || '';
} }
historiaText = historiaText.replace(/<think>[\s\S]*?<\/think>/gi, '').trim(); historiaText = historiaText.replace(/<think>[\s\S]*?<\/think>/gi, '').trim();
if (!historiaText) throw new Error('Falha ao inventar história'); if (!historiaText) throw new Error('Falha ao inventar história (texto vazio)');
const dbRes = await dbPool.query( const dbRes = await dbPool.query(
`INSERT INTO escola.historias (usuario_id, faixa_etaria, paragrafos, personagens, estilo, tema, historia) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id`, `INSERT INTO escola.historias (usuario_id, faixa_etaria, paragrafos, personagens, estilo, tema, historia) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id`,
@@ -1415,7 +1423,7 @@ ${idadeInstrucao}
res.json({ id: dbRes.rows[0].id, historia: historiaText }); res.json({ id: dbRes.rows[0].id, historia: historiaText });
} catch (err) { } catch (err) {
console.error('Erro História:', err); console.error('Erro História:', err);
res.status(500).json({ error: 'Erro ao inventar história.' }); res.status(500).json({ error: 'Erro ao inventar história: ' + err.message });
} }
}); });