* Set up request and response interceptors
(client: Client)
| 67 | * Set up request and response interceptors |
| 68 | */ |
| 69 | function setupInterceptors(client: Client): void { |
| 70 | client.interceptors.request.use( |
| 71 | config => { |
| 72 | logger.request(null, config.method || 'unknown', config.url || 'unknown', { |
| 73 | params: config.params, |
| 74 | body: config.data, |
| 75 | }); |
| 76 | return config; |
| 77 | }, |
| 78 | error => { |
| 79 | return Promise.reject(error); |
| 80 | } |
| 81 | ); |
| 82 | |
| 83 | client.interceptors.response.use( |
| 84 | response => { |
| 85 | logger.response(null, response.status, response.config?.url || 'unknown', { |
| 86 | data: response.data, |
| 87 | }); |
| 88 | return response; |
| 89 | }, |
| 90 | error => { |
| 91 | if (axios.isAxiosError(error)) { |
| 92 | const status = error.response?.status; |
| 93 | const method = error.config?.method?.toUpperCase(); |
| 94 | const url = error.config?.url || 'unknown'; |
| 95 | |
| 96 | logger.error(null, 'API Request Failed', { |
| 97 | method, |
| 98 | url, |
| 99 | status, |
| 100 | message: error.message, |
| 101 | code: error.code, |
| 102 | }); |
| 103 | } else { |
| 104 | logger.error(null, 'Non-Axios Error in Response Interceptor', { |
| 105 | message: error instanceof Error ? error.message : String(error), |
| 106 | }); |
| 107 | } |
| 108 | return Promise.reject(error); |
| 109 | } |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Add retry functionality to the client |
no test coverage detected