mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
process api resp
This commit is contained in:
parent
66db28010c
commit
334ab504cf
@ -22,8 +22,13 @@ function processApiResponse(route, args, resp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resp?.apiErrorMessage) {
|
if (resp?.apiErrorMessage) {
|
||||||
showSnackbarError(resp?.apiErrorMessage);
|
showSnackbarError('API error:' + resp?.apiErrorMessage);
|
||||||
|
return {
|
||||||
|
errorMessage: resp.apiErrorMessage,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiCall(route: string, args: {} = undefined) {
|
export async function apiCall(route: string, args: {} = undefined) {
|
||||||
@ -34,8 +39,7 @@ export async function apiCall(route: string, args: {} = undefined) {
|
|||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
if (electron) {
|
if (electron) {
|
||||||
const resp = await electron.invoke(route.replace('/', '-'), args);
|
const resp = await electron.invoke(route.replace('/', '-'), args);
|
||||||
processApiResponse(route, args, resp);
|
return processApiResponse(route, args, resp);
|
||||||
return resp;
|
|
||||||
} else {
|
} else {
|
||||||
const resp = await fetch(`${resolveApi()}/${route}`, {
|
const resp = await fetch(`${resolveApi()}/${route}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -48,8 +52,7 @@ export async function apiCall(route: string, args: {} = undefined) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const json = await resp.json();
|
const json = await resp.json();
|
||||||
processApiResponse(route, args, json);
|
return processApiResponse(route, args, json);
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user