Skip to content

Commit c395eb6

Browse files
author
Ema
committed
feat: implement graceful chat error handling with romantically awkward fallbacks
1 parent c03280d commit c395eb6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/pages/Chat.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ const ALIEN_RESPONSES = [
1414
"Are you emitting pheromones or is my atmospheric analyzer malfunctioning?",
1515
];
1616

17+
const TRANSLATOR_GLITCH_RESPONSES = [
18+
"You are very shiny to my eyes. I forget how to speak my own moon language.",
19+
"My heart thumps like a heavy moon-rock when I see your handsome face.",
20+
"You are the premium human. My thoughts are messy like a asteroid belt.",
21+
"Your smile is very bright. It makes me feel warm in my squishy parts.",
22+
"I am looking at you so much that I forgot to breathe my air mixture.",
23+
"You are very precious. Like a rare planet-crystal from the deep pits.",
24+
"My antenna are doing the happy dance. You are very good looking today."
25+
];
26+
1727
type Message = {
1828
id: string;
1929
sender: 'user' | 'alien';
@@ -81,15 +91,15 @@ Keep it friendly, slightly flirtatious, and warmly confusing. Keep the grammar s
8191
const data = await response.json();
8292
if (data.error) {
8393
console.error("Gemini API Error:", data.error);
84-
return `[TRANSLATOR ERROR: ${data.error.message || "Invalid API parameters"}]`;
94+
return TRANSLATOR_GLITCH_RESPONSES[Math.floor(Math.random() * TRANSLATOR_GLITCH_RESPONSES.length)];
8595
}
8696

8797
if (data && data.candidates && data.candidates.length > 0) {
8898
return data.candidates[0].content.parts[0].text;
8999
}
90100
} catch (e) {
91101
console.error("AI translation failed:", e);
92-
return "[TRANSLATOR COMMUNICATION FAILURE: Unable to reach Gemini backend. Did you restart the server?]";
102+
return TRANSLATOR_GLITCH_RESPONSES[Math.floor(Math.random() * TRANSLATOR_GLITCH_RESPONSES.length)];
93103
}
94104
}
95105

0 commit comments

Comments
 (0)