itube-specs 0.0.483 → 0.0.484
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
|
+
import { getHeaders } from "h3";
|
|
3
|
+
import type { FetchOptions } from "ofetch";
|
|
2
4
|
|
|
3
|
-
/** Класс для работы с серверным API (бекенд) */
|
|
4
5
|
export class ServerApiHelper {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const response = await $fetch(url, {
|
|
16
|
-
headers: getHeaders(event),
|
|
17
|
-
...requestOptions,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Если бэкенд всегда возвращает { data: ... }
|
|
21
|
-
return response?.data as T;
|
|
22
|
-
|
|
23
|
-
// Альтернатива: если иногда просто объект — можно так
|
|
24
|
-
// return response as T;
|
|
25
|
-
} catch (err: any) {
|
|
26
|
-
throw new Error(`Cannot fetch: ${err?.data || err?.message || err}`);
|
|
6
|
+
public static async fetch<T>(url: string, event: H3Event, requestOptions?: FetchOptions): Promise<T> {
|
|
7
|
+
try {
|
|
8
|
+
const response = await $fetch<{ data: T }>(url, {
|
|
9
|
+
headers: getHeaders(event),
|
|
10
|
+
...requestOptions,
|
|
11
|
+
});
|
|
12
|
+
return response.data;
|
|
13
|
+
} catch (error: any) {
|
|
14
|
+
throw new Error(`Cannot fetch ${url}: ${error?.data ?? error?.message ?? error}`);
|
|
15
|
+
}
|
|
27
16
|
}
|
|
28
|
-
}
|
|
29
17
|
}
|