Commit 982efe39 authored by Tristan Cavelier's avatar Tristan Cavelier

Error thrown by subCommands.js are improved

parent 192c14a1
...@@ -9,14 +9,28 @@ var getCommand = function(spec, my) { ...@@ -9,14 +9,28 @@ var getCommand = function(spec, my) {
}; };
that.validateState = function() { that.validateState = function() {
if (!that.getDocId()) { if (typeof that.getDocId() === "string" && that.getDocId() === "") {
that.error({ that.error({
status:20,statusText:'Document Id Required', "status": 20,
error:'document_id_required', "statusText": "Document Id Required",
message:'No document id.',reason:'no document id' "error": "document_id_required",
"message": "The document id is not provided",
"reason": "Document id is undefined"
}); });
return false; 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; return true;
}; };
......
...@@ -10,6 +10,21 @@ var postCommand = function(spec, my) { ...@@ -10,6 +10,21 @@ var postCommand = function(spec, my) {
return 'post'; return 'post';
}; };
that.validateState = function () {
if (typeof that.getAttachmentId() !== "undefined") {
that.error({
"status": 21,
"statusText": "Invalid Document Id",
"error": "Invalid Document Id",
"message": "The document id contains '/' characters "+
"which are forbidden",
"reason": "Document id contains '/' character(s)"
});
return false;
}
return true;
};
that.executeOn = function(storage) { that.executeOn = function(storage) {
storage.post (that); storage.post (that);
}; };
......
...@@ -11,15 +11,27 @@ var putAttachmentCommand = function(spec, my) { ...@@ -11,15 +11,27 @@ var putAttachmentCommand = function(spec, my) {
that.executeOn = function (storage) { that.executeOn = function (storage) {
storage.putAttachment (that); storage.putAttachment (that);
}; };
that.validateState = function () { that.validateState = function () {
if (typeof that.getContent() !== 'string') { if (typeof that.getAttachmentId() === "undefined") {
that.error({ that.error({
status:22,statusText:'Content Required', "status": 22,
error:'content_required', "statusText": "Attachment Id Required",
message:'No data to put.',reason:'no data to put' "error": "attachment_id_required",
"message": "The attachment id must be set",
"reason": "Attachment id not set"
}); });
return false; return false;
} }
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 true; return true;
}; };
......
...@@ -10,6 +10,31 @@ var putCommand = function(spec, my) { ...@@ -10,6 +10,31 @@ var putCommand = function(spec, my) {
return 'put'; return 'put';
}; };
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() !== "undefined") {
that.error({
"status": 21,
"statusText": "Invalid Document Id",
"error": "invalid_document_id",
"message": "The document id contains '/' characters "+
"which are forbidden",
"reason": "Document id contains '/' character(s)"
});
return false;
}
return true;
};
that.executeOn = function(storage) { that.executeOn = function(storage) {
storage.put (that); storage.put (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