Download apps/whatsapp-worker/src/services/api-client.ts from safetrack/edtech: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/whatsapp-worker/src/services/api-client.ts
- Command line
-
hf download hf://spaces/safetrack/edtech/apps/whatsapp-worker/src/services/api-client.ts
-
curl -L -o api-client.ts https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/whatsapp-worker/src/services/api-client.ts
1.02 kB
| import axios from 'axios'; | |
| import { getApiUrl, getAdminApiKey } from '../config'; | |
| import { logger } from '../logger'; | |
| const AI_API_BASE_URL = getApiUrl().replace(/\/$/, ""); | |
| const apiKey = getAdminApiKey(); | |
| /** | |
| * Centralized Axios client for internal API communication (Edtech API). | |
| * Standardizes headers, timeouts, and error logging. | |
| */ | |
| export const apiClient = axios.create({ | |
| baseURL: AI_API_BASE_URL, | |
| timeout: 30000, // 30s timeout for AI operations | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${apiKey}` | |
| } | |
| }); | |
| // Response interceptor for consistent error logging | |
| apiClient.interceptors.response.use( | |
| (response) => response, | |
| (error) => { | |
| const url = error.config?.url; | |
| const status = error.response?.status; | |
| const message = error.response?.data?.error || error.message; | |
| logger.error(`[API_CLIENT] Error calling ${url} (Status: ${status}): ${message}`); | |
| return Promise.reject(error); | |
| } | |
| ); | |