Commit 447c8c4d authored by Tristan Cavelier's avatar Tristan Cavelier

Enhance error detection accuracy

parent 73508dd2
......@@ -21,7 +21,7 @@ var command = function(spec, my) {
priv.tried = 0;
priv.doc = spec.doc || {};
priv.docid = spec.docid || spec.doc._id || '';
priv.docid = spec.docid || priv.doc._id;
priv.option = spec.options || {};
priv.callbacks = spec.callbacks || {};
priv.success = priv.callbacks.success || function (){};
......@@ -75,6 +75,9 @@ var command = function(spec, my) {
* @return {string} The document id
*/
that.getDocId = function () {
if (typeof priv.docid !== "string") {
return undefined;
}
return priv.docid.split('/')[0];
};
......@@ -84,6 +87,9 @@ var command = function(spec, my) {
* @return {string} The attachment id
*/
that.getAttachmentId = function () {
if (typeof priv.docid !== "string") {
return undefined;
}
return priv.docid.split('/')[1];
};
......@@ -157,7 +163,8 @@ var command = function(spec, my) {
* @param {object} storage The storage.
*/
that.validate = function (storage) {
if (!priv.docid.match(/^[^\/]+([\/][^\/]+)?$/)) {
if (typeof priv.docid === "string" &&
!priv.docid.match(/^[^\/]+([\/][^\/]+)?$/)) {
that.error({
status:21,statusText:'Invalid Document Id',
error:'invalid_document_id',
......
......@@ -9,7 +9,7 @@ var getCommand = function(spec, my) {
};
that.validateState = function() {
if (typeof that.getDocId() === "string" && that.getDocId() === "") {
if (!(typeof that.getDocId() === "string" && that.getDocId() !== "")) {
that.error({
"status": 20,
"statusText": "Document Id Required",
......
......@@ -15,7 +15,7 @@ var postCommand = function(spec, my) {
that.error({
"status": 21,
"statusText": "Invalid Document Id",
"error": "Invalid Document Id",
"error": "invalid_document_id",
"message": "The document id contains '/' characters "+
"which are forbidden",
"reason": "Document id contains '/' character(s)"
......
......@@ -13,7 +13,7 @@ var putAttachmentCommand = function(spec, my) {
};
that.validateState = function () {
if (typeof that.getAttachmentId() === "undefined") {
if (typeof that.getAttachmentId() !== "string") {
that.error({
"status": 22,
"statusText": "Attachment Id Required",
......
......@@ -11,7 +11,7 @@ var putCommand = function(spec, my) {
};
that.validateState = function () {
if (typeof that.getDocId() === "string" && that.getDocId() === "") {
if (!(typeof that.getDocId() === "string" && that.getDocId() !== "")) {
that.error({
"status": 20,
"statusText": "Document Id Required",
......
......@@ -8,6 +8,32 @@ var removeCommand = function(spec, my) {
return 'remove';
};
that.validateState = function() {
if (!(typeof that.getDocId() === "string" && that.getDocId() !== "")) {
that.error({
"status": 20,
"statusText": "Document Id Required",
"error": "document_id_required",
"message": "The document id is not provided",
"reason": "Document id is undefined"
});
return false;
}
if (typeof that.getAttachmentId() === "string") {
if (that.getAttachmentId() === "") {
that.error({
"status": 23,
"statusText": "Invalid Attachment Id",
"error": "invalid_attachment_id",
"message": "The attachment id must not be an empty string",
"reason": "Attachment id is empty"
});
}
return false;
}
return true;
};
that.executeOn = function(storage) {
storage.remove (that);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment