/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
packages/framework/src/utils/http.utils.ts
42 строки
1 KB
Adam Chmara
chore(root): apply biome formatter & linter fixes NV-6436 (#8838)
31 июл 2025, 14:59
Не верифицирован
31 июл 2025, 14:59
855fb8f
Код
Авторство
О чём код?
import { BridgeError, MissingSecretKeyError, PlatformError } from '../errors'; import { checkIsResponseError } from '../shared'; export const initApiClient = (secretKey: string, apiUrl: string) => { if (!secretKey) { throw new MissingSecretKeyError(); } return { post: async <T = unknown>(route: string, data: Record<string, unknown>): Promise<T> => { const response = await fetch(`${apiUrl}/v1${route}`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `ApiKey ${secretKey}`, }, body: JSON.stringify(data), }); const resJson = await response.json(); if (response.ok) { return resJson as T; } else if (checkIsResponseError(resJson)) { throw new PlatformError(resJson.statusCode, resJson.error, resJson.message); } else { throw new BridgeError(resJson); } }, delete: async <T = unknown>(route: string): Promise<T> => { return ( await fetch(`${apiUrl}/v1${route}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', Authorization: `ApiKey ${secretKey}`, }, }) ).json() as T; }, }; };