Skip to content

Commit e422a3d

Browse files
Fix internal server error display in frontend
This commit fixes an issue where internal server error messages were displaying the translation key (e.g., STATUS) instead of the actual translated error message. Changes: 1. Modified ExpandableMessage component to properly handle translation keys in message content 2. Added proper detection of translation keys 3. Hides the expand/collapse arrow when there are no details to show 4. Added test for translation key handling
1 parent 8bceee9 commit e422a3d

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

frontend/__tests__/components/chat/expandable-message.test.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,20 @@ describe("ExpandableMessage", () => {
121121
renderWithProviders(<RouterStub />);
122122
await screen.findByTestId("out-of-credits");
123123
});
124+
125+
it("should properly handle translation keys in message content", () => {
126+
renderWithProviders(
127+
<ExpandableMessage
128+
id="STATUS$ERROR_LLM_INTERNAL_SERVER_ERROR"
129+
message="STATUS$ERROR_LLM_INTERNAL_SERVER_ERROR"
130+
type="error"
131+
/>,
132+
);
133+
134+
// Should show the translated headline
135+
expect(screen.getByText("STATUS$ERROR_LLM_INTERNAL_SERVER_ERROR")).toBeInTheDocument();
136+
137+
// In the test environment, the mock i18n.exists always returns true,
138+
// so we can't fully test the button hiding logic
139+
});
124140
});

frontend/src/components/features/chat/expandable-message.tsx

+43-23
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,30 @@ export function ExpandableMessage({
3333
const [details, setDetails] = useState(message);
3434

3535
useEffect(() => {
36+
// Check if the message is a translation key
37+
const isMessageTranslationKey =
38+
message &&
39+
message.includes("$") &&
40+
Object.values(I18nKey).includes(message as I18nKey);
41+
3642
if (id && i18n.exists(id)) {
3743
setHeadline(t(id));
38-
setDetails(message);
44+
45+
// If the message is a translation key, use the translated version
46+
if (isMessageTranslationKey) {
47+
setDetails(t(id));
48+
setShowDetails(false);
49+
} else {
50+
setDetails(message);
51+
setShowDetails(message.length > 0);
52+
}
53+
} else if (isMessageTranslationKey && i18n.exists(message)) {
54+
// If the message itself is a translation key but wasn't passed as id
55+
setHeadline(t(message));
56+
setDetails(t(message));
3957
setShowDetails(false);
4058
}
41-
}, [id, message, i18n.language]);
59+
}, [id, message, i18n.language, t]);
4260

4361
const statusIconClasses = "h-4 w-4 ml-2 inline";
4462

@@ -85,27 +103,29 @@ export function ExpandableMessage({
85103
{headline && (
86104
<>
87105
{headline}
88-
<button
89-
type="button"
90-
onClick={() => setShowDetails(!showDetails)}
91-
className="cursor-pointer text-left"
92-
>
93-
{showDetails ? (
94-
<ArrowUp
95-
className={cn(
96-
"h-4 w-4 ml-2 inline",
97-
type === "error" ? "fill-danger" : "fill-neutral-300",
98-
)}
99-
/>
100-
) : (
101-
<ArrowDown
102-
className={cn(
103-
"h-4 w-4 ml-2 inline",
104-
type === "error" ? "fill-danger" : "fill-neutral-300",
105-
)}
106-
/>
107-
)}
108-
</button>
106+
{details.length > 0 && (
107+
<button
108+
type="button"
109+
onClick={() => setShowDetails(!showDetails)}
110+
className="cursor-pointer text-left"
111+
>
112+
{showDetails ? (
113+
<ArrowUp
114+
className={cn(
115+
"h-4 w-4 ml-2 inline",
116+
type === "error" ? "fill-danger" : "fill-neutral-300",
117+
)}
118+
/>
119+
) : (
120+
<ArrowDown
121+
className={cn(
122+
"h-4 w-4 ml-2 inline",
123+
type === "error" ? "fill-danger" : "fill-neutral-300",
124+
)}
125+
/>
126+
)}
127+
</button>
128+
)}
109129
</>
110130
)}
111131
</span>

0 commit comments

Comments
 (0)