- {(() => {
- // Check if the error contains JSON
- try {
- // Try to parse as JSON first
- const parsed = JSON.parse(error);
- return (
-
- {JSON.stringify(parsed, null, 2)}
-
- );
- } catch {
- // If not JSON, check if it looks like a code/technical error
- if (
- error.includes("{") ||
- error.includes("Error:") ||
- error.length > 100
- ) {
- return (
-
- {error}
-
- );
- }
- // Otherwise, display as regular text
- return (
-
{error}
- );
- }
- })()}
+
+
+
{error.error || "Failed to take screenshot"}
+ {error.details && (
+
+ Details: {error.details}
+
+ )}
+ {error.code && (
+
+ Error Code: {error.code}
+
+ )}
+
)}
diff --git a/components/chat/ApiErrorDisplay.test.tsx b/components/chat/ApiErrorDisplay.test.tsx
new file mode 100644
index 0000000..794f622
--- /dev/null
+++ b/components/chat/ApiErrorDisplay.test.tsx
@@ -0,0 +1,420 @@
+/**
+ * @jest-environment jsdom
+ */
+import React from 'react';
+import { render, screen, fireEvent } from '@testing-library/react';
+import ApiErrorDisplay from './ApiErrorDisplay';
+
+describe('ApiErrorDisplay Component', () => {
+ describe('Basic error rendering', () => {
+ it('should render error with just a message', () => {
+ const error = { message: 'Something went wrong' };
+ render(