From ccb786e26be9e19219aa398d635b5f8f7b1c5090 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Mon, 19 Jun 2017 15:17:27 +0200 Subject: [PATCH] Implemented the 'MustIgnore' error skip in the 'IfParser' --- lib/helper/IfParser.js | 23 ++++++++++++++++++----- src/helper/IfParser.ts | 22 +++++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/helper/IfParser.js b/lib/helper/IfParser.js index 8c6a8ca2..bdb7531d 100644 --- a/lib/helper/IfParser.js +++ b/lib/helper/IfParser.js @@ -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); }); }; } @@ -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); }); }); }; diff --git a/src/helper/IfParser.ts b/src/helper/IfParser.ts index bb0996e8..fbbc6ac5 100644 --- a/src/helper/IfParser.ts +++ b/src/helper/IfParser.ts @@ -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); }) } } @@ -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); }) } } @@ -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); }) } } @@ -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); }); }) }