Files
bee-dashboard/src/utils/net.ts
T
Adam Uhlíř 109e07b097 feat: sentry integration (#385)
* feat: sentry support

* ci: depscheck
2022-06-16 20:32:53 +02:00

34 lines
790 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import axios from 'axios'
export function getJson<T extends Record<string, any>>(url: string): Promise<T> {
return sendRequest(url, 'GET') as Promise<T>
}
export function postJson(url: string, data?: Record<string, any>): Promise<Record<string, unknown>> {
return sendRequest(url, 'POST', data)
}
export async function sendRequest(
url: string,
method: 'GET' | 'POST',
data?: Record<string, unknown>,
): Promise<Record<string, any>> {
const authorization = localStorage.getItem('apiKey')
if (!authorization) {
throw Error('API key not found in local storage')
}
const headers = {
authorization,
}
const response = await axios(url, {
method,
headers,
data,
})
return response.data
}