Skip to content

Commit

Permalink
Implemented the 'MustIgnore' error skip in the 'IfParser'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 19, 2017
1 parent 164022b commit ccb786e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
23 changes: 18 additions & 5 deletions lib/helper/IfParser.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IResource_1 = require("../resource/IResource");
var Errors_1 = require("../Errors");
var url = require("url");
function NoLock() {
return function (r, callback) {
r.getLocks(function (e, locks) {
callback(e, locks ? locks.length === 0 : false);
if (e === Errors_1.Errors.MustIgnore)
callback(null, true);
else
callback(e, locks ? locks.length === 0 : false);
});
};
}
function Token(token) {
return function (r, callback) {
r.getLock(token, function (e, lock) {
callback(e, !!lock && !e);
if (e === Errors_1.Errors.MustIgnore)
callback(null, true);
else
callback(e, !!lock && !e);
});
};
}
function Tag(tag) {
return function (r, callback) {
r.lastModifiedDate(function (e, lastModifiedDate) {
callback(e, !e && IResource_1.ETag.createETag(lastModifiedDate) === tag);
if (e === Errors_1.Errors.MustIgnore)
callback(null, true);
else
callback(e, !e && IResource_1.ETag.createETag(lastModifiedDate) === tag);
});
};
}
Expand Down Expand Up @@ -119,8 +129,11 @@ function parseIfHeader(ifHeader) {
if (!a.path)
a.actions(r, done);
else
arg.server.getResourceFromPath(a.path, function (e, resource) {
a.actions(resource, done);
arg.server.getResourceFromPath(arg, a.path, function (e, resource) {
if (e)
done(e, null);
else
a.actions(resource, done);
});
});
};
Expand Down
22 changes: 17 additions & 5 deletions src/helper/IfParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function NoLock()
{
return function(r : IResource, callback : FnReturn) {
r.getLocks((e, locks) => {
callback(e, locks ? locks.length === 0 : false);
if(e === Errors.MustIgnore)
callback(null, true);
else
callback(e, locks ? locks.length === 0 : false);
})
}
}
Expand All @@ -18,7 +21,10 @@ function Token(token : string)
{
return function(r : IResource, callback : FnReturn) {
r.getLock(token, (e, lock) => {
callback(e, !!lock && !e);
if(e === Errors.MustIgnore)
callback(null, true);
else
callback(e, !!lock && !e);
})
}
}
Expand All @@ -27,7 +33,10 @@ function Tag(tag : string)
{
return function(r : IResource, callback : FnReturn) {
r.lastModifiedDate((e, lastModifiedDate) => {
callback(e, !e && ETag.createETag(lastModifiedDate) === tag);
if(e === Errors.MustIgnore)
callback(null, true);
else
callback(e, !e && ETag.createETag(lastModifiedDate) === tag);
})
}
}
Expand Down Expand Up @@ -159,8 +168,11 @@ export function parseIfHeader(ifHeader : string)
if(!a.path)
a.actions(r, done);
else
arg.server.getResourceFromPath(a.path, (e, resource) => {
a.actions(resource, done);
arg.server.getResourceFromPath(arg, a.path, (e, resource) => {
if(e)
done(e, null);
else
a.actions(resource, done);
});
})
}
Expand Down

0 comments on commit ccb786e

Please sign in to comment.