Skip to content

Commit

Permalink
Associate field name with the error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 17, 2016
1 parent 4173d39 commit 040e824
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@ function addRule (globalRules, schema, blueprint, name) {
return schema
}

function createTypeError (message, field) {
var error = new TypeError(message)
error.field = field
return error
}

function throwTypeError (name, type, message) {
if (!message || isBoolean(message)) {
message = `Expected {${type}} for '${name}'.`
}
throw new TypeError(message)
throw createTypeError(message, name)
}

function throwValidationError (name, value, description) {
var msg
var message

if (description) {
msg = description.replace('{VALUE}', value)
message = description.replace('{VALUE}', value)
} else {
msg = `Fail '${value}' validation for '${name}'.`
message = `Fail '${value}' validation for '${name}'.`
}

throw new TypeError(msg)
throw createTypeError(message, name)
}

function Osom (schemaBlueprint, globalRules) {
Expand Down

0 comments on commit 040e824

Please sign in to comment.