mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Improve AI content generation by handling OpenRouter API errors
Enhance the OpenRouterService to log detailed error responses and validate the structure of the API response before processing, addressing issues with AI content generation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/cIV2GBh
This commit is contained in:
1 parent
1b3f7d7532
commit
a0d519dec0
1 file changed
+9
@@ -50,10 +50,19 @@ export class OpenRouterService {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('OpenRouter API Error Response:', errorText);
|
||||
throw new Error(`OpenRouter API error: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('OpenRouter API Response:', JSON.stringify(data, null, 2));
|
||||
|
||||
if (!data.choices || !data.choices[0]) {
|
||||
console.error('Invalid OpenRouter response structure:', data);
|
||||
throw new Error('Réponse invalide de l\'API OpenRouter. Vérifiez votre clé API et votre modèle.');
|
||||
}
|
||||
|
||||
const content = data.choices[0]?.message?.content || "";
|
||||
|
||||
return this.parseGeneratedText(content);
|
||||
|
||||
Reference in new issue
Block a user