Skip to content

Commit

Permalink
Updated field errors on standard hayepeaeye method calling
Browse files Browse the repository at this point in the history
  • Loading branch information
Daryl Rowland committed Sep 2, 2014
1 parent 4c7bcc2 commit 5592704
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions haypeaeye.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var callMethod = function(methodToCall, req, res) {
if ((param.required || param.index != undefined) && (!exports.getAttribute(req, param.name, methodToCall.method))) {
// Check this isn't a false boolean
if (!(param.type && param.type == exports.Boolean)) {
res.send(400, {error: "Required attribute not present, '" + param.name + "'"});
res.send(400, {error: "Required attribute not present, '" + param.name + "'", field_errors: [{field: param.name, message: "You must provide a value"}]});
return;
}
}
Expand All @@ -206,7 +206,7 @@ var callMethod = function(methodToCall, req, res) {
// Begin more detailed validations
if (param.type && param.type == exports.Number) {
if (isNaN(rawValue)) {
res.send(400, {error: "Attribute '" + param.name + "' is not a valid number"});
res.send(400, {error: "Attribute '" + param.name + "' is not a valid number", field_errors: [{field: param.name, message: "Invalid number"}]});
return;
}
}
Expand All @@ -215,7 +215,7 @@ var callMethod = function(methodToCall, req, res) {
if (param.type && param.type == exports.Date) {
var dateValue = moment(rawValue, exports.DATE_FORMAT);
if (!dateValue.isValid()) {
res.send(400, {error: "Attribute '" + param.name + "' is not a valid date. Format should be YYYY-MM-DD HH:mm"});
res.send(400, {error: "Attribute '" + param.name + "' is not a valid date. Format should be YYYY-MM-DD HH:mm", field_errors: [{field: param.name, message: "Invalid date"}]});
return;
}
}
Expand All @@ -233,15 +233,15 @@ var callMethod = function(methodToCall, req, res) {
}

if (!validValue) {
res.send(400, {error: "Attribute '" + param.name + "' is not a valid value"});
res.send(400, {error: "Attribute '" + param.name + "' is not a valid value", field_errors: [{field: param.name, message: "Invalid value"}]});
return;
}
}

// Arrays
if (param.type && param.type == exports.Array) {
if (!(rawValue instanceof Array)) {
res.send(400, {error: "Attribute '" + param.name + "' is not a valid array"});
res.send(400, {error: "Attribute '" + param.name + "' is not a valid array", field_errors: [{field: param.name, message: "Invalid array"}]});
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haypeaeye",
"version": "0.2.6",
"version": "0.2.7",
"description": "Library for Express that lets you easily create APIs that self document and validate",
"main": "haypeaeye.js",
"repository": {
Expand Down

0 comments on commit 5592704

Please sign in to comment.