(fetch: () => Promise<any>)
| 81 | } |
| 82 | |
| 83 | async function fetchInterceptor<T>(fetch: () => Promise<any>): Promise<AxiosResponse<IApiWrapper & { data: T }>> { |
| 84 | let respData: IApiWrapper & { data: T }; |
| 85 | try { |
| 86 | if (!isInitialized()) { |
| 87 | await initializeDatabusWasm(); |
| 88 | } |
| 89 | respData = await fetch(); |
| 90 | } catch (e) { |
| 91 | console.error(e); |
| 92 | respData = {} as IAxiosResponse<T>['data']; |
| 93 | throw new Error('fetch failure for wasm'); |
| 94 | } |
| 95 | |
| 96 | if (isClient() && window.__global_handle_response) { |
| 97 | return window.__global_handle_response({ |
| 98 | data: respData, |
| 99 | }, undefined, undefined); |
| 100 | } |
| 101 | return { |
| 102 | data: respData |
| 103 | } as unknown as AxiosResponse<IApiWrapper & { data: T }>; |
| 104 | } |
| 105 | |
| 106 | const initializeDatabusWasm = async () => { |
| 107 | if (!isClient()) { |
no test coverage detected