@metis-w/api-client
Version:
Modern TypeScript HTTP API client with dynamic routes, parameterized endpoints, interceptors, and advanced features
53 lines • 1.61 kB
JavaScript
/**
* Request logging interceptor
* @param options - Logging configuration
*/
export const requestLoggingInterceptor = (options = {}) => {
const { logRequests = true, logLevel = "info" } = options;
return (config) => {
if (logRequests) {
console[logLevel](`🚀 API Request: ${config.method?.toUpperCase()} ${config.url}`, {
data: config.data,
params: config.params,
headers: config.headers,
});
}
return config;
};
};
/**
* Response logging interceptor
* @param options - Logging configuration
*/
export const responseLoggingInterceptor = (options = {}) => {
const { logResponses = true, logLevel = "info" } = options;
return (response) => {
if (logResponses) {
const status = response.success ? "✅" : "❌";
console[logLevel](`${status} API Response:`, {
success: response.success,
data: response.data,
error: response.error,
});
}
return response;
};
};
/**
* Error logging interceptor
* @param options - Logging configuration
*/
export const errorLoggingInterceptor = (options = {}) => {
const { logErrors = true, logLevel = "error" } = options;
return (error) => {
if (logErrors) {
console[logLevel]("💥 API Error:", {
message: error.message,
type: error.type,
originalError: error.originalError,
});
}
return error;
};
};
//# sourceMappingURL=logging.js.map