Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit a3d8ddfd
authored
Oct 17, 2013
by
Thanasis Polychronakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom validators yield an Error instance and error args are transported as is
1 parent
775dd7b8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
lib/dao-validator.js
lib/dao-validator.js
View file @
a3d8ddf
...
...
@@ -10,6 +10,9 @@ var DaoValidator = module.exports = function(model, options) {
this
.
options
=
options
}
/** @define {string} The error key for arguments as passed by custom validators */
DaoValidator
.
RAW_KEY_NAME
=
'__raw'
DaoValidator
.
prototype
.
validate
=
function
()
{
var
self
=
this
...
...
@@ -24,13 +27,16 @@ DaoValidator.prototype.validate = function() {
emitter
.
emit
(
'success'
)
})
.
error
(
function
(
err
)
{
var
errors
=
{}
var
error
=
new
Error
(
'Validation error'
)
error
[
DaoValidator
.
RAW_KEY_NAME
]
=
[]
Utils
.
_
.
each
(
err
,
function
(
value
)
{
Utils
.
_
.
extend
(
errors
,
value
)
error
[
DaoValidator
.
RAW_KEY_NAME
].
push
(
value
[
DaoValidator
.
RAW_KEY_NAME
])
delete
value
[
DaoValidator
.
RAW_KEY_NAME
]
Utils
.
_
.
extend
(
error
,
value
)
})
emitter
.
emit
(
'success'
,
errors
)
emitter
.
emit
(
'success'
,
error
)
})
}).
run
()
}
...
...
@@ -72,8 +78,11 @@ var validateModel = function() {
var
next
=
function
(
err
)
{
if
(
err
)
{
var
error
=
{}
error
[
validatorType
]
=
[
err
]
var
error
=
{};
error
[
DaoValidator
.
RAW_KEY_NAME
]
=
err
;
var
msg
=
((
err
instanceof
Error
)
?
err
.
message
:
err
)
error
[
validatorType
]
=
[
msg
]
emitter
.
emit
(
'error'
,
error
)
}
else
{
emitter
.
emit
(
'success'
)
...
...
@@ -155,7 +164,7 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
try
{
details
.
apply
(
this
.
model
,
callArgs
)
}
catch
(
ex
)
{
return
next
(
ex
.
message
)
return
next
(
ex
)
}
if
(
!
isAsync
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment