Antonio-Maranhao commented on a change in pull request #1065: Remove JQuery 
uses from documents addon
URL: https://github.com/apache/couchdb-fauxton/pull/1065#discussion_r174189166
 
 

 ##########
 File path: app/addons/documents/resources.js
 ##########
 @@ -120,31 +118,26 @@ Documents.BulkDeleteDocCollection = 
FauxtonAPI.Collection.extend({
   },
 
   bulkDelete: function () {
-    var payload = this.createPayload(this.toJSON()),
-        promise = FauxtonAPI.Deferred(),
-        that = this;
-
-    $.ajax({
-      type: 'POST',
-      url: this.url(),
-      contentType: 'application/json',
-      dataType: 'json',
-      data: JSON.stringify(payload),
-    }).then(function (res) {
-      that.handleResponse(res, promise);
-    }).fail(function () {
-      var ids = _.reduce(that.toArray(), function (acc, doc) {
-        acc.push(doc.id);
-        return acc;
-      }, []);
-      that.trigger('error', ids);
-      promise.reject(ids);
+    const payload = this.createPayload(this.toJSON());
+    const promise = new FauxtonAPI.Promise((resolve, reject) => {
+      post(this.url(), payload).then(res => {
+        if (res.error) {
 
 Review comment:
   The issue is unlike `$.ajax()`, `fetch` doesn't raise an error for 4xx, 5xx 
codes. I could handle errors inside `then()` as you suggested, but I should 
also add a `catch()` to handle `fetch()` errors as well (e.g. connection lost).
   Considering both types of errors are handled pretty much in the same way, I 
found the easiest is to raise an Error and keep error handling inside `catch()` 
because it seems more logical. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to