PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.0.5
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.0.5
1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / frontend / vue / utils / helpers / index.ts
hostinger-reach / frontend / vue / utils / helpers Last commit date
index.ts 10 months ago
index.ts
28 lines
1 import { AxiosResponse } from 'axios';
2
3 interface BaseApiResponse<T> {
4 success?: boolean;
5 data?: T;
6 error?: Error | string | null;
7 }
8
9 export const generateCorrelationId = (): string => `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
10
11 export const asyncCall = async <T>(
12 promise: Promise<AxiosResponse<BaseApiResponse<T>>>
13 ): Promise<[T | null, Error | null]> => {
14 try {
15 const response = await promise;
16
17 if (!response.data.error || (Array.isArray(response.data.error) && !response.data.error.length)) {
18 const responseData = response.data.data || response.data;
19
20 return [responseData as T, null];
21 }
22
23 return [null, response.data.error as Error];
24 } catch (error) {
25 return [null, error as Error];
26 }
27 };
28