Allow fetching NoContent resources
authorFrank Bessou <frank.bessou@logilab.fr>
Thu, 13 Apr 2017 10:45:07 +0200
changeset 110 432a59a73c7d
parent 109 f9fbff23f4a9
child 111 a3d7461ef63a
Allow fetching NoContent resources
src/Api.js
--- a/src/Api.js	Thu Apr 13 10:39:45 2017 +0200
+++ b/src/Api.js	Thu Apr 13 10:45:07 2017 +0200
@@ -30,8 +30,10 @@
             headers: {Accept: 'application/json'}});
         return this.fetch(fullUrl, options)
             .then(response => {
-                if(response.headers.get("content-type") &&
-                        response.headers.get("content-type").toLowerCase().indexOf("application/json") >= 0) {
+                const contentType = response.headers.get("content-type");
+                if(response.status === 204) {
+                    return response;
+                } else if (contentType && contentType.toLowerCase().indexOf("application/json") >= 0) {
                     return response;
                 }
                 const method = options.method || 'GET';