Explorar o código

fix(restClient): make axios call() async

drac %!s(int64=5) %!d(string=hai) anos
pai
achega
ecca2a18ae
Modificáronse 1 ficheiros con 11 adicións e 4 borrados
  1. 11 4
      webui/ovpm/src/utils/restClient.js

+ 11 - 4
webui/ovpm/src/utils/restClient.js

@@ -68,7 +68,7 @@ export class API {
   // @param {bool} performAuth - if set to true, send Authorization header with the authToken
   // @param {func} onSuccess - success handler to call
   // @param {func} onFailure - failure handler to call
-  call(endpointName, data, performAuth, onSuccess, onFailure) {
+  async call(endpointName, data, performAuth, onSuccess, onFailure) {
     // validate endpointName
     if (!(endpointName in this.endpoints)) {
       throw new Error(endpointName + " is not available in " + this.endpoints);
@@ -88,8 +88,15 @@ export class API {
     }
 
     // actually perform the call
-    axios(callConf)
-      .then(onSuccess)
-      .catch(onFailure);
+    // axios(callConf)
+    //   .then(onSuccess)
+    //   .catch(onFailure);
+
+    try {
+      const res = await axios(callConf);
+      onSuccess(res);
+    } catch (err) {
+      onFailure(err);
+    }
   }
 }