Fix some incompatible calls in URL test button

This commit is contained in:
LASER-Yi 2021-06-02 10:02:02 +08:00
parent e9ef40c629
commit 7687013270
1 changed files with 19 additions and 7 deletions

View File

@ -11,17 +11,29 @@ type UrlTestResponse =
};
class RequestUtils {
urlTest(
async urlTest(
protocol: string,
url: string,
params?: any
): Promise<UrlTestResponse> {
return new Promise<UrlTestResponse>((resolve, reject) => {
apis.axios
.get(`../test/${protocol}/${url}api/system/status`, { params })
.then((result) => resolve(result.data))
.catch(reject);
});
try {
const result = await apis.axios.get<UrlTestResponse>(
`../test/${protocol}/${url}api/system/status`,
{ params }
);
const { data } = result;
if (data.status && data.version) {
return data;
} else {
throw new Error("Cannot get response, fallback to v3 api");
}
} catch (e) {
const result = await apis.axios.get<UrlTestResponse>(
`../test/${protocol}/${url}api/v3/system/status`,
{ params }
);
return result.data;
}
}
}