Skip to content

Commit 81a6cba

Browse files
committed
Add timeout and error handling to health checks
- Prevent hanging health checks with 10 second timeout - Improved error handling with fallback states - Better logging for debugging health check issues
1 parent e740943 commit 81a6cba

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

packages/web/src/hooks/useHealthCheck.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export function useHealthCheck(options: UseHealthCheckOptions = {}) {
5454
const API_BASE_URL = import.meta.env.VITE_API_URL || ''; // Use relative URLs to leverage Vite proxy
5555

5656
const checkHealth = useCallback(async () => {
57+
const timeoutId = setTimeout(() => {
58+
setLoading(false);
59+
setError('Health check timed out');
60+
}, 10000); // 10 second timeout
61+
5762
try {
5863
setLoading(true);
5964
setError(null);
@@ -96,9 +101,23 @@ export function useHealthCheck(options: UseHealthCheckOptions = {}) {
96101

97102
setLastChecked(new Date());
98103
} catch (err) {
99-
setError(err instanceof Error ? err.message : 'Health check failed');
104+
const errorMessage = err instanceof Error ? err.message : 'Health check failed';
100105
console.error('Health check error:', err);
106+
setError(errorMessage);
107+
108+
// Set fallback status when there's an error
109+
setHealth({
110+
status: 'unhealthy',
111+
timestamp: new Date().toISOString(),
112+
services: {
113+
graphql: { status: 'unknown', port: 0 },
114+
neo4j: { status: 'unknown', uri: '' },
115+
mcp: { status: 'unknown', port: 3128, capabilities: [] }
116+
}
117+
});
118+
setMcpStatus({ connected: false, error: errorMessage });
101119
} finally {
120+
clearTimeout(timeoutId);
102121
setLoading(false);
103122
}
104123
}, [API_BASE_URL]);

0 commit comments

Comments
 (0)