Skip to content

Commit

Permalink
Simple errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 6, 2016
1 parent 9081f04 commit a66a129
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
15 changes: 3 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ var isString = require('lodash.isstring')
var reduce = require('lodash.reduce')
var assign = require('lodash.assign')
var flow = require('lodash.flow')
var Whoops = require('whoops')
var chaste = require('chaste')

var ENOTYPE = Whoops.create('ENOTYPE')
var EARDENT = Whoops.create('EARDENT')

// TODO: Add disable casting {casting: false}
// TODO: Add validation like mongoose
// validate: {
Expand Down Expand Up @@ -60,13 +56,8 @@ function addRule (schema, blueprint, name) {
function throwTypeError (name, type, required) {
var msg
if (isArray(required) && isString(required[1])) msg = required[1]
else msg = 'Need to provide {' + type + "} for '" + name + "' field."
var err = ENOTYPE(msg)
throw err
}

function throwError () {
throw EARDENT.apply([EARDENT, arguments])
else msg = 'Expected a ' + type + " for '" + name + "'."
throw new TypeError(msg)
}

function Ardent (schemaBlueprint) {
Expand Down Expand Up @@ -99,7 +90,7 @@ function Ardent (schemaBlueprint) {
else if (!isFunction(rule.default)) value = rule.default
else value = rule.default()

objSchema[name] = applyFilters(value, throwError)
objSchema[name] = applyFilters(value)
return objSchema
}, {})
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"lodash.isarray": "~4.0.0",
"lodash.isfunction": "~3.0.8",
"lodash.isstring": "~4.0.1",
"lodash.reduce": "~4.3.0",
"whoops": "~2.0.1"
"lodash.reduce": "~4.3.0"
},
"devDependencies": {
"browserify": "latest",
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('schema defintion', function () {
}

var ardent = Ardent(schema)
var errMessage = "Need to provide {String} for 'age' field."
var errMessage = "Expected a String for 'age'."
;(function () { ardent() }).should.throw(errMessage)
})

Expand Down

0 comments on commit a66a129

Please sign in to comment.