Description
Is your feature request related to a problem? Please describe.
The current logging mechanism does not capture detailed error information when API calls fail, making it difficult to diagnose issues and improve the user experience.
Describe the solution you'd like
Implement an enhanced logging system that captures detailed error messages, including the API endpoint, request parameters, and response status codes. This can be achieved by integrating a structured logging library such as Winston or Bunyan.
Code Example
const logger = require('winston');
async function makeApiCall(endpoint, params) {
try {
const response = await fetch(endpoint, { method: 'GET', body: JSON.stringify(params) });
if (!response.ok) {
throw new Error(`API Error: ${response.status} - ${response.statusText}`);
}
return await response.json();
} catch (error) {
logger.error('API call failed', { endpoint, params, error: error.message });
throw error;
}
}
Describe alternatives you've considered
Using the current logging mechanism, which only captures the error message without context.
Additional context
Enhanced logging will provide better visibility into API failures, allowing for quicker diagnosis and resolution of issues, which will ultimately improve the user experience.