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 f0c01eda
authored
Jul 23, 2014
by
Brian Romanko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating the instance validator errors to use the new ValidationErrorItem
1 parent
8be24f37
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
29 deletions
lib/instance-validator.js
lib/sequelize.js
lib/instance-validator.js
View file @
f0c01ed
...
...
@@ -115,10 +115,10 @@ var InstanceValidator = module.exports = function(modelInstance, options) {
/**
* All errors will be stored here from the validations.
*
* @type {
Sequelize.error
} Will contain keys that correspond to attributes which will
* @type {
Array
} Will contain keys that correspond to attributes which will
* be Arrays of Errors.
*/
this
.
errors
=
new
sequelizeError
.
ValidationError
(
'Validation error'
)
;
this
.
errors
=
[]
;
/** @type {boolean} Indicates if validations are in progress */
this
.
inProgress
=
false
;
...
...
@@ -139,15 +139,14 @@ InstanceValidator.prototype.validate = function() {
throw
new
Error
(
'Validations already in progress.'
);
}
this
.
inProgress
=
true
;
this
.
errors
=
new
sequelizeError
.
ValidationError
(
'Validation error'
);
var
self
=
this
;
return
Promise
.
settle
([
self
.
_builtinValidators
(),
self
.
_customValidators
()
]).
then
(
function
()
{
if
(
Object
.
keys
(
self
.
errors
)
.
length
)
{
return
self
.
errors
;
if
(
self
.
errors
.
length
)
{
return
new
sequelizeError
.
ValidationError
(
'Validation error'
,
self
.
errors
)
;
}
return
new
Promise
(
function
(
resolve
)
{
...
...
@@ -356,26 +355,14 @@ InstanceValidator.prototype._validateSchema = function(rawAttribute, field, valu
var
error
;
if
(
rawAttribute
.
allowNull
===
false
&&
((
value
===
null
)
||
(
value
===
undefined
)))
{
error
=
new
sequelizeError
.
ValidationError
(
field
+
' cannot be null'
);
error
.
path
=
field
;
error
.
value
=
value
;
error
.
type
=
error
.
message
=
'notNull Violation'
;
if
(
!
this
.
errors
.
hasOwnProperty
(
field
))
{
this
.
errors
[
field
]
=
[];
}
this
.
errors
[
field
].
push
(
error
);
error
=
new
sequelizeError
.
ValidationErrorItem
(
field
+
' cannot be null'
,
'notNull Violation'
,
field
,
value
);
this
.
errors
.
push
(
error
);
}
if
(
rawAttribute
.
type
===
DataTypes
.
STRING
)
{
if
(
Array
.
isArray
(
value
)
||
(
_
.
isObject
(
value
)
&&
!
value
.
_isSequelizeMethod
))
{
error
=
new
sequelizeError
.
ValidationError
(
field
+
' cannot be an array or an object'
);
error
.
path
=
field
;
error
.
value
=
value
;
error
.
type
=
error
.
message
=
'string violation'
;
if
(
!
this
.
errors
.
hasOwnProperty
(
field
))
{
this
.
errors
[
field
]
=
[];
}
this
.
errors
[
field
].
push
(
error
);
error
=
new
sequelizeError
.
ValidationErrorItem
(
field
+
' cannot be an array or an object'
,
'string violation'
,
field
,
value
);
this
.
errors
.
push
(
error
);
}
}
};
...
...
@@ -409,14 +396,9 @@ InstanceValidator.prototype._handleSettledResult = function(field, promiseInspec
* @private
*/
InstanceValidator
.
prototype
.
_pushError
=
function
(
isBuiltin
,
errorKey
,
rawError
)
{
if
(
!
this
.
errors
.
hasOwnProperty
(
errorKey
))
{
this
.
errors
[
errorKey
]
=
[];
}
var
error
=
new
sequelizeError
.
ValidationError
();
var
message
=
rawError
.
message
||
rawError
||
'Validation error'
;
var
error
=
new
sequelizeError
.
ValidationErrorItem
(
message
,
'Validation error'
,
errorKey
,
rawError
);
error
[
InstanceValidator
.
RAW_KEY_NAME
]
=
rawError
;
error
.
message
=
rawError
.
message
||
rawError
||
'Validation error'
;
this
.
errors
[
errorKey
]
.
push
(
error
);
this
.
errors
.
push
(
error
);
};
lib/sequelize.js
View file @
f0c01ed
...
...
@@ -238,6 +238,13 @@ module.exports = (function() {
sequelizeErrors
.
ValidationError
;
/**
* Describes a validation error on an instance path
* @property ValidationErrorItem
*/
Sequelize
.
prototype
.
ValidationErrorItem
=
Sequelize
.
ValidationErrorItem
=
sequelizeErrors
.
ValidationErrorItem
;
/**
* Returns the specified dialect.
*
* @return {String} The specified dialect.
...
...
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