diff options
author | LASER-Yi <[email protected]> | 2021-06-02 10:02:02 +0800 |
---|---|---|
committer | LASER-Yi <[email protected]> | 2021-06-02 10:02:02 +0800 |
commit | 768701327025471e04619db80ead6ebe6c6e08c0 (patch) | |
tree | 1c0cb8835d57285026d74d4804e53f78ebe40951 | |
parent | e9ef40c6296a1e2e0c81b0ee42e5d2a2955c5f60 (diff) | |
download | bazarr-768701327025471e04619db80ead6ebe6c6e08c0.tar.gz bazarr-768701327025471e04619db80ead6ebe6c6e08c0.zip |
Fix some incompatible calls in URL test button
-rw-r--r-- | frontend/src/apis/utils.ts | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/frontend/src/apis/utils.ts b/frontend/src/apis/utils.ts index 9601a692b..f45b53150 100644 --- a/frontend/src/apis/utils.ts +++ b/frontend/src/apis/utils.ts @@ -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; + } } } |