17944: Request the vocabulary exclusively from the new controller's endpoint.
[arvados-workbench2.git] / src / common / webdav.ts
index 17032768fd00436ef92cb4b63d156d0456ddc442..758a5e18e1e9ad44015b9a802d0e532e70ba3d76 100644 (file)
@@ -2,6 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { customEncodeURI } from "./url";
+
 export class WebDAV {
 
     defaults: WebDAVDefaults = {
@@ -75,7 +77,8 @@ export class WebDAV {
             r.open(config.method,
                 `${this.defaults.baseURL
                     ? this.defaults.baseURL+'/'
-                    : ''}${config.url}`);
+                    : ''}${customEncodeURI(config.url)}`);
+
             const headers = { ...this.defaults.headers, ...config.headers };
             Object
                 .keys(headers)
@@ -85,14 +88,16 @@ export class WebDAV {
                 r.upload.addEventListener('progress', config.onUploadProgress);
             }
 
+            // This event gets triggered on *any* server response
             r.addEventListener('load', () => {
-                if (r.status === 404) {
+                if (r.status >= 400) {
                     return reject(r);
                 } else {
                     return resolve(r);
                 }
             });
 
+            // This event gets triggered on network errors
             r.addEventListener('error', () => {
                 return reject(r);
             });