* Send single request to Tianji application API (fallback when batch is disabled)
( serverUrl: string, type: 'event' | 'identify', payload: ApplicationEventPayload | ApplicationIdentifyPayload )
| 234 | * Send single request to Tianji application API (fallback when batch is disabled) |
| 235 | */ |
| 236 | async function sendSingleRequest( |
| 237 | serverUrl: string, |
| 238 | type: 'event' | 'identify', |
| 239 | payload: ApplicationEventPayload | ApplicationIdentifyPayload |
| 240 | ): Promise<void> { |
| 241 | try { |
| 242 | const response = await fetch(`${serverUrl}/api/application/send`, { |
| 243 | method: 'POST', |
| 244 | headers: { |
| 245 | 'Content-Type': 'application/json', |
| 246 | }, |
| 247 | body: JSON.stringify({ |
| 248 | type, |
| 249 | payload, |
| 250 | }), |
| 251 | }); |
| 252 | |
| 253 | if (!response.ok) { |
| 254 | const errorText = await response.text(); |
| 255 | throw new Error(`Failed to send application ${type}: ${errorText}`); |
| 256 | } |
| 257 | } catch (error) { |
| 258 | console.error(`Error sending application ${type}:`, error); |
| 259 | return; // As event tracking SDK, should not throw error which maybe cause crash |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Send batch request to Tianji application API |
no test coverage detected