Enhance error handling in AIEngine and update ResourceDebugOverlay
- Added error type handling in AIEngine for better error categorization during model configuration and execution. - Updated _handle_error method to accept and log error types. - Improved ResourceDebugOverlay to silently ignore 404 responses from the metrics endpoint, preventing unnecessary logging and retries. - Refactored authStore to utilize fetchAPI for automatic token handling and improved error logging without throwing exceptions.
This commit is contained in:
@@ -128,7 +128,7 @@ export default function ResourceDebugOverlay({ enabled }: ResourceDebugOverlayPr
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
// Silently handle 404s and other errors - metrics might not exist for all requests
|
||||
// Silently handle 404s and other errors - metrics might not exist for all requests
|
||||
try {
|
||||
const response = await nativeFetch.call(window, `${API_BASE_URL}/v1/system/request-metrics/${requestId}/`, {
|
||||
method: 'GET',
|
||||
@@ -136,6 +136,11 @@ export default function ResourceDebugOverlay({ enabled }: ResourceDebugOverlayPr
|
||||
credentials: 'include', // Include session cookies for authentication
|
||||
});
|
||||
|
||||
// Silently ignore 404s - metrics endpoint might not exist for all requests
|
||||
if (response.status === 404) {
|
||||
return; // Don't log or retry 404s
|
||||
}
|
||||
|
||||
if (response.ok) {
|
||||
const responseData = await response.json();
|
||||
// Extract data from unified API response format: {success: true, data: {...}}
|
||||
|
||||
@@ -192,32 +192,23 @@ export const useAuthStore = create<AuthState>()(
|
||||
}
|
||||
|
||||
try {
|
||||
const API_BASE_URL = import.meta.env.VITE_BACKEND_URL || 'https://api.igny8.com/api';
|
||||
const token = state.token || getAuthToken();
|
||||
// Use fetchAPI which handles token automatically and extracts data from unified format
|
||||
const { fetchAPI } = await import('../services/api');
|
||||
const response = await fetchAPI('/v1/auth/me/');
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/v1/auth/me/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { 'Authorization': `Bearer ${token}` } : {}),
|
||||
},
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok || !data.success) {
|
||||
throw new Error(data.message || 'Failed to refresh user data');
|
||||
// fetchAPI extracts data field, so response is {user: {...}}
|
||||
if (!response || !response.user) {
|
||||
throw new Error('Failed to refresh user data');
|
||||
}
|
||||
|
||||
// Update user data with latest from server
|
||||
// This ensures account/plan changes are reflected immediately
|
||||
set({ user: data.user });
|
||||
set({ user: response.user });
|
||||
} catch (error: any) {
|
||||
// If refresh fails, don't logout - just log the error
|
||||
// User might still be authenticated, just couldn't refresh data
|
||||
console.warn('Failed to refresh user data:', error);
|
||||
throw new Error(error.message || 'Failed to refresh user data');
|
||||
// Don't throw - just log the warning to prevent error accumulation
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user