diff --git a/src/jio.storage/davstorage.js b/src/jio.storage/davstorage.js index cb5d5e6e515f097dae20dba2f697ce883d7fad11..942bbdd62f22d66180e8f77d8ab2cab14a351f2a 100644 --- a/src/jio.storage/davstorage.js +++ b/src/jio.storage/davstorage.js @@ -196,13 +196,24 @@ DavStorage.prototype.putAttachment = function (id, name, blob) { + var that = this; id = restrictDocumentId(id); restrictAttachmentId(name); - return ajax(this, { - type: "PUT", - url: this._url + id + name, - data: blob - }); + + return new RSVP.Queue() + .push(function () { + return ajax(that, { + type: "PUT", + url: that._url + id + name, + data: blob + }); + }) + .push(undefined, function (error) { + if (error.target.status === 403) { + throw new jIO.util.jIOError("Cannot access subdocument", 404); + } + throw error; + }); }; DavStorage.prototype.getAttachment = function (id, name) { diff --git a/test/jio.storage/davstorage.tests.js b/test/jio.storage/davstorage.tests.js index c3ddd9a870ee22308c384fc39d3b08f5cc916a99..5927cb9989a3ffa462f2e1c548e3d287c2ba6e30 100644 --- a/test/jio.storage/davstorage.tests.js +++ b/test/jio.storage/davstorage.tests.js @@ -765,6 +765,29 @@ }); }); + test("putAttachment to inexisting directory: expecting a 404", function () { + var blob = new Blob(["foo"]), + url = domain + "/inexistent_dir/attachment1"; + this.server.respondWith("PUT", url, [403, {"": ""}, ""]); + stop(); + expect(3); + + this.jio.putAttachment( + "/inexistent_dir/", + "attachment1", + blob + ) + .fail(function (error) { + ok(error instanceof jIO.util.jIOError); + equal(error.message, "Cannot access subdocument"); + equal(error.status_code, 404); + }) + .always(function () { + start(); + }); + }); + + test("putAttachment document", function () { var blob = new Blob(["foo"]), url = domain + "/putAttachment1/attachment1",