Fix: Prevent console message loop on maintenance updates
The console was generating excessive messages after schedule maintenance updates.
This commit is contained in:
@@ -35,4 +35,52 @@ const api = {
|
||||
}
|
||||
};
|
||||
|
||||
// Mock fetch override for development
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = async (url, options = {}) => {
|
||||
// Check if this is an API request to our mock endpoints
|
||||
if (typeof url === 'string' && url.startsWith('/api/')) {
|
||||
console.log('Intercepting API request:', url, options);
|
||||
|
||||
try {
|
||||
let body = {};
|
||||
|
||||
// Properly handle different body types
|
||||
if (options.body) {
|
||||
if (typeof options.body === 'string') {
|
||||
body = JSON.parse(options.body);
|
||||
} else {
|
||||
// Handle ReadableStream or other BodyInit types
|
||||
const bodyText = await new Response(options.body).text();
|
||||
body = bodyText ? JSON.parse(bodyText) : {};
|
||||
}
|
||||
}
|
||||
|
||||
const result = await api.handleRequest(url, options.method || 'GET', body);
|
||||
|
||||
// Create a proper Response object
|
||||
return new Response(JSON.stringify(result.json), {
|
||||
status: result.status,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in API handler:', error);
|
||||
return new Response(JSON.stringify({
|
||||
success: false,
|
||||
message: 'Internal server error'
|
||||
}), {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// For all other requests, use the original fetch
|
||||
return originalFetch(url, options);
|
||||
};
|
||||
|
||||
export default api;
|
||||
Reference in New Issue
Block a user