mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
recursive retry on GET /v1/packages (#313)
* #311 recursive retry on GET /v1/packages * #308 add recursive retry on all GET requests --------- Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
cbe19fa138
commit
c4e69ea89b
2 changed files with 28 additions and 16 deletions
|
@ -25,7 +25,7 @@ const { ipcRenderer, shell } = window.require("electron");
|
|||
|
||||
export async function getPackages(): Promise<GUIPackage[]> {
|
||||
const [packages, installedPackages] = await Promise.all([
|
||||
apiGet<Package[]>("packages", { nocache: "true" }),
|
||||
apiGet<Package[]>("packages"),
|
||||
ipcRenderer.invoke("get-installed-packages") as { version: string; full_name: string }[]
|
||||
]);
|
||||
|
||||
|
|
|
@ -5,25 +5,37 @@ import { getSession } from "$libs/stores/auth";
|
|||
|
||||
export const baseUrl = "https://api.tea.xyz/v1";
|
||||
|
||||
export async function get<T>(urlPath: string, params?: { [key: string]: string }) {
|
||||
console.log(`GET /v1/${urlPath}`);
|
||||
export async function get<T>(
|
||||
urlPath: string,
|
||||
params?: { [key: string]: string }
|
||||
): Promise<T | null> {
|
||||
try {
|
||||
console.log(`GET /v1/${urlPath}`);
|
||||
|
||||
const [session] = await Promise.all([getSession()]);
|
||||
const [session] = await Promise.all([getSession()]);
|
||||
|
||||
const headers =
|
||||
session?.device_id && session?.user
|
||||
? await getHeaders(`GET/${urlPath}`, session)
|
||||
: { Authorization: "public " };
|
||||
const headers =
|
||||
session?.device_id && session?.user
|
||||
? await getHeaders(`GET/${urlPath}`, session)
|
||||
: { Authorization: "public " };
|
||||
|
||||
const req = await axios.request({
|
||||
method: "GET",
|
||||
baseURL: "https://api.tea.xyz",
|
||||
url: ["v1", ...urlPath.split("/")].filter((p) => p).join("/"),
|
||||
headers,
|
||||
params
|
||||
});
|
||||
const req = await axios.request({
|
||||
method: "GET",
|
||||
baseURL: "https://api.tea.xyz",
|
||||
url: ["v1", ...urlPath.split("/")].filter((p) => p).join("/"),
|
||||
headers,
|
||||
params
|
||||
});
|
||||
|
||||
return req.data as T;
|
||||
if (req.status == 200) {
|
||||
return req.data as T;
|
||||
} else {
|
||||
return await get<T>(urlPath, params || {});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("ERROR", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function getHeaders(path: string, session: Session) {
|
||||
|
|
Loading…
Reference in a new issue