MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / bindApiClient

Function bindApiClient

packages/agentflow/src/infrastructure/api/client.ts:13–58  ·  view source on GitHub ↗
(apiBaseUrl: string, token?: string, requestInterceptor?: RequestInterceptor)

Source from the content-addressed store, hash-verified

11 * @param requestInterceptor - Optional callback to customize outgoing requests
12 */
13export function bindApiClient(apiBaseUrl: string, token?: string, requestInterceptor?: RequestInterceptor): DeduplicatedClient {
14 const headers: Record<string, string> = {
15 'Content-Type': 'application/json'
16 }
17
18 if (token) {
19 headers['Authorization'] = `Bearer ${token}`
20 }
21
22 const client = axios.create({
23 baseURL: `${apiBaseUrl}/api/v1`,
24 headers
25 })
26
27 // Add request interceptor for consumer customization
28 client.interceptors.request.use(
29 (config) => {
30 if (!requestInterceptor) return config
31 try {
32 return requestInterceptor(config)
33 } catch (error) {
34 console.error('[Agentflow] requestInterceptor threw:', error)
35 return config
36 }
37 },
38 (error) => Promise.reject(error)
39 )
40
41 // Add response interceptor for error handling
42 client.interceptors.response.use(
43 (response) => response,
44 (error) => {
45 if (error.response?.status === 401) {
46 console.error('[Agentflow] 401 Authentication error:', {
47 url: error.config?.url,
48 message: error.response?.data?.message || error.message,
49 hasToken: !!token,
50 tokenLength: token?.length
51 })
52 }
53 return Promise.reject(error)
54 }
55 )
56
57 return withDeduplication(client)
58}
59
60export type { AxiosInstance }

Callers 2

ApiProviderFunction · 0.90
client.test.tsFile · 0.90

Calls 2

withDeduplicationFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected