feat: tratamento de erros detalhado para APIs de midia MiniMax
This commit is contained in:
@@ -379,7 +379,8 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
|||||||
const imageUrl = imgData.data?.image_url?.[0];
|
const imageUrl = imgData.data?.image_url?.[0];
|
||||||
|
|
||||||
if (!imageUrl) {
|
if (!imageUrl) {
|
||||||
throw new Error('Nenhuma imagem foi gerada pela API do MiniMax');
|
const baseRespMsg = imgData.base_resp?.status_msg || (imgData.base_resp?.status_code ? `Erro MiniMax (Código: ${imgData.base_resp.status_code})` : null);
|
||||||
|
throw new Error(baseRespMsg || 'Nenhuma imagem foi gerada pela API do MiniMax');
|
||||||
}
|
}
|
||||||
|
|
||||||
res.write(`data: ${JSON.stringify({ type: 'image', url: imageUrl, originalPrompt: promptText })}\n\n`);
|
res.write(`data: ${JSON.stringify({ type: 'image', url: imageUrl, originalPrompt: promptText })}\n\n`);
|
||||||
@@ -470,7 +471,8 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!audioUrl) {
|
if (!audioUrl) {
|
||||||
throw new Error('Nenhum áudio de música foi gerado pela API da MiniMax');
|
const baseRespMsg = musicData.base_resp?.status_msg || (musicData.base_resp?.status_code ? `Erro MiniMax (Código: ${musicData.base_resp.status_code})` : null);
|
||||||
|
throw new Error(baseRespMsg || 'Nenhum áudio de música foi gerado pela API da MiniMax');
|
||||||
}
|
}
|
||||||
|
|
||||||
res.write(`data: ${JSON.stringify({ type: 'audio', url: audioUrl, originalPrompt: promptText })}\n\n`);
|
res.write(`data: ${JSON.stringify({ type: 'audio', url: audioUrl, originalPrompt: promptText })}\n\n`);
|
||||||
@@ -547,7 +549,8 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
|||||||
const taskId = jobData.task_id;
|
const taskId = jobData.task_id;
|
||||||
|
|
||||||
if (!taskId) {
|
if (!taskId) {
|
||||||
throw new Error('Nenhum ID de tarefa foi retornado pelo MiniMax');
|
const baseRespMsg = jobData.base_resp?.status_msg || (jobData.base_resp?.status_code ? `Erro MiniMax (Código: ${jobData.base_resp.status_code})` : null);
|
||||||
|
throw new Error(baseRespMsg || 'Nenhum ID de tarefa foi retornado pelo MiniMax');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Polling do status do vídeo
|
// Polling do status do vídeo
|
||||||
@@ -577,10 +580,17 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
|||||||
if (fileResp.ok) {
|
if (fileResp.ok) {
|
||||||
const fileData = await fileResp.json();
|
const fileData = await fileResp.json();
|
||||||
videoUrl = fileData.file?.download_url;
|
videoUrl = fileData.file?.download_url;
|
||||||
|
if (!videoUrl) {
|
||||||
|
const baseRespMsg = fileData.base_resp?.status_msg || 'Falha ao recuperar download URL do arquivo de vídeo';
|
||||||
|
throw new Error(baseRespMsg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const errText = await fileResp.text();
|
||||||
|
throw new Error(`Falha ao obter arquivo do vídeo: ${errText}`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (checkData.status === 'Fail') {
|
} else if (checkData.status === 'Fail') {
|
||||||
throw new Error('A API da MiniMax falhou em renderizar este vídeo.');
|
throw new Error(checkData.base_resp?.status_msg || 'A API da MiniMax falhou em renderizar este vídeo.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user