remove more logs

This commit is contained in:
EthanHealy01 2025-07-30 14:25:06 +01:00
parent 8eaffcd604
commit f72bf3b86c

View File

@ -15,55 +15,32 @@ export function useEndpointEnabled(endpoint: string): {
const fetchEndpointStatus = async () => { const fetchEndpointStatus = async () => {
if (!endpoint) { if (!endpoint) {
console.log('[Endpoint Validation] No endpoint provided, setting to null');
setEnabled(null); setEnabled(null);
setLoading(false); setLoading(false);
return; return;
} }
console.log(`[Endpoint Validation] Starting validation for endpoint: ${endpoint}`);
try { try {
setLoading(true); setLoading(true);
setError(null); setError(null);
const url = `/api/v1/config/endpoint-enabled?endpoint=${encodeURIComponent(endpoint)}`; const response = await fetch(`/api/v1/config/endpoint-enabled?endpoint=${encodeURIComponent(endpoint)}`);
console.log(`[Endpoint Validation] Fetching from URL: ${url}`);
const response = await fetch(url);
console.log(`[Endpoint Validation] Response received for ${endpoint}:`, {
status: response.status,
statusText: response.statusText,
ok: response.ok,
headers: Object.fromEntries(response.headers.entries())
});
if (!response.ok) { if (!response.ok) {
const errorMessage = `Failed to check endpoint: ${response.status} ${response.statusText}`; throw new Error(`Failed to check endpoint: ${response.status} ${response.statusText}`);
console.error(`[Endpoint Validation] Error response for ${endpoint}:`, errorMessage);
throw new Error(errorMessage);
} }
const isEnabled: boolean = await response.json(); const isEnabled: boolean = await response.json();
console.log(`[Endpoint Validation] Endpoint ${endpoint} status:`, isEnabled);
setEnabled(isEnabled); setEnabled(isEnabled);
} catch (err) { } catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred'; const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
console.error(`[Endpoint Validation] Failed to check endpoint ${endpoint}:`, err);
console.error(`[Endpoint Validation] Error details:`, {
name: err instanceof Error ? err.name : 'Unknown',
message: errorMessage,
stack: err instanceof Error ? err.stack : undefined
});
setError(errorMessage); setError(errorMessage);
} finally { } finally {
setLoading(false); setLoading(false);
console.log(`[Endpoint Validation] Completed validation for ${endpoint}, loading: false`);
} }
}; };
useEffect(() => { useEffect(() => {
console.log(`[Endpoint Validation] useEffect triggered for endpoint: ${endpoint}`);
fetchEndpointStatus(); fetchEndpointStatus();
}, [endpoint]); }, [endpoint]);
@ -91,13 +68,10 @@ export function useMultipleEndpointsEnabled(endpoints: string[]): {
const fetchAllEndpointStatuses = async () => { const fetchAllEndpointStatuses = async () => {
if (!endpoints || endpoints.length === 0) { if (!endpoints || endpoints.length === 0) {
console.log('[Endpoint Validation] No endpoints provided for batch validation');
setEndpointStatus({}); setEndpointStatus({});
setLoading(false); setLoading(false);
return; return;
} }
console.log(`[Endpoint Validation] Starting batch validation for ${endpoints.length} endpoints:`, endpoints);
try { try {
setLoading(true); setLoading(true);
@ -105,52 +79,33 @@ export function useMultipleEndpointsEnabled(endpoints: string[]): {
// Use batch API for efficiency // Use batch API for efficiency
const endpointsParam = endpoints.join(','); const endpointsParam = endpoints.join(',');
const url = `/api/v1/config/endpoints-enabled?endpoints=${encodeURIComponent(endpointsParam)}`;
console.log(`[Endpoint Validation] Batch fetch URL: ${url}`);
const response = await fetch(url); const response = await fetch(`/api/v1/config/endpoints-enabled?endpoints=${encodeURIComponent(endpointsParam)}`);
console.log(`[Endpoint Validation] Batch response received:`, {
status: response.status,
statusText: response.statusText,
ok: response.ok,
headers: Object.fromEntries(response.headers.entries())
});
if (!response.ok) { if (!response.ok) {
const errorMessage = `Failed to check endpoints: ${response.status} ${response.statusText}`; throw new Error(`Failed to check endpoints: ${response.status} ${response.statusText}`);
console.error(`[Endpoint Validation] Batch error response:`, errorMessage);
throw new Error(errorMessage);
} }
const statusMap: Record<string, boolean> = await response.json(); const statusMap: Record<string, boolean> = await response.json();
console.log(`[Endpoint Validation] Batch endpoint statuses:`, statusMap);
setEndpointStatus(statusMap); setEndpointStatus(statusMap);
} catch (err) { } catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred'; const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
console.error('[Endpoint Validation] Failed to check multiple endpoints:', err);
console.error('[Endpoint Validation] Batch error details:', {
name: err instanceof Error ? err.name : 'Unknown',
message: errorMessage,
stack: err instanceof Error ? err.stack : undefined
});
setError(errorMessage); setError(errorMessage);
console.error('Failed to check multiple endpoints:', err);
// Fallback: assume all endpoints are disabled on error // Fallback: assume all endpoints are disabled on error
const fallbackStatus = endpoints.reduce((acc, endpoint) => { const fallbackStatus = endpoints.reduce((acc, endpoint) => {
acc[endpoint] = false; acc[endpoint] = false;
return acc; return acc;
}, {} as Record<string, boolean>); }, {} as Record<string, boolean>);
console.log('[Endpoint Validation] Using fallback status (all disabled):', fallbackStatus);
setEndpointStatus(fallbackStatus); setEndpointStatus(fallbackStatus);
} finally { } finally {
setLoading(false); setLoading(false);
console.log(`[Endpoint Validation] Completed batch validation for ${endpoints.length} endpoints, loading: false`);
} }
}; };
useEffect(() => { useEffect(() => {
const endpointsKey = endpoints.join(','); const endpointsKey = endpoints.join(',');
console.log(`[Endpoint Validation] Batch useEffect triggered for endpoints: ${endpointsKey}`);
fetchAllEndpointStatuses(); fetchAllEndpointStatuses();
}, [endpoints.join(',')]); // Re-run when endpoints array changes }, [endpoints.join(',')]); // Re-run when endpoints array changes