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 9c7500d7
authored
Jul 23, 2014
by
Brian Romanko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing the error object inheritence
1 parent
2bb1845c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
17 deletions
lib/errors.js
test/error.test.js
lib/errors.js
View file @
9c7500d
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
* @fileOverview The Error Objects produced by Sequelize.
* @fileOverview The Error Objects produced by Sequelize.
*/
*/
var
util
=
require
(
'util'
);
var
error
=
module
.
exports
=
{};
var
error
=
module
.
exports
=
{};
/**
/**
...
@@ -13,9 +12,17 @@ var error = module.exports = {};
...
@@ -13,9 +12,17 @@ var error = module.exports = {};
* @constructor
* @constructor
*/
*/
error
.
BaseError
=
function
()
{
error
.
BaseError
=
function
()
{
Error
.
apply
(
this
,
arguments
);
var
tmp
=
Error
.
apply
(
this
,
arguments
);
tmp
.
name
=
this
.
name
=
'SequelizeBaseError'
;
this
.
stack
=
tmp
.
stack
;
this
.
message
=
tmp
.
message
;
return
this
;
};
};
util
.
inherits
(
error
.
BaseError
,
Error
);
error
.
BaseError
.
prototype
=
Object
.
create
(
Error
.
prototype
,
{
constructor
:
{
value
:
error
.
BaseError
}
});
/**
/**
...
@@ -25,5 +32,10 @@ util.inherits(error.BaseError, Error);
...
@@ -25,5 +32,10 @@ util.inherits(error.BaseError, Error);
*/
*/
error
.
ValidationError
=
function
()
{
error
.
ValidationError
=
function
()
{
error
.
BaseError
.
apply
(
this
,
arguments
);
error
.
BaseError
.
apply
(
this
,
arguments
);
this
.
name
=
'SequelizeValidationError'
;
return
this
;
};
};
util
.
inherits
(
error
.
ValidationError
,
error
.
BaseError
);
error
.
ValidationError
.
prototype
=
Object
.
create
(
error
.
BaseError
.
prototype
,
{
constructor
:
{
value
:
error
.
ValidationError
}
});
\ No newline at end of file
test/error.test.js
View file @
9c7500d
...
@@ -2,20 +2,19 @@
...
@@ -2,20 +2,19 @@
var
chai
=
require
(
'chai'
)
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
)
,
Support
=
require
(
__dirname
+
'/support'
)
,
Sequelize
=
Support
.
Sequelize
,
Sequelize
=
Support
.
Sequelize
;
// , sinon = require('sinon')
chai
.
config
.
includeStack
=
true
chai
.
config
.
includeStack
=
true
;
describe
(
Support
.
getTestDialectTeaser
(
"Sequelize Errors"
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
"Sequelize Errors"
),
function
()
{
describe
(
'API Surface'
,
function
()
{
describe
(
'API Surface'
,
function
()
{
it
(
'Should have the Error constructors exposed'
,
function
()
{
it
(
'Should have the Error constructors exposed'
,
function
()
{
expect
(
Sequelize
).
to
.
have
.
property
(
'Error'
)
expect
(
Sequelize
).
to
.
have
.
property
(
'Error'
)
;
expect
(
Sequelize
).
to
.
have
.
property
(
'ValidationError'
)
expect
(
Sequelize
).
to
.
have
.
property
(
'ValidationError'
)
;
var
sequelize
=
new
Sequelize
();
var
sequelize
=
new
Sequelize
();
expect
(
sequelize
).
to
.
have
.
property
(
'Error'
)
expect
(
sequelize
).
to
.
have
.
property
(
'Error'
)
;
expect
(
sequelize
).
to
.
have
.
property
(
'ValidationError'
)
expect
(
sequelize
).
to
.
have
.
property
(
'ValidationError'
)
;
})
})
;
it
(
'Sequelize Errors instances should be instances of Error'
,
function
()
{
it
(
'Sequelize Errors instances should be instances of Error'
,
function
()
{
var
error
=
new
Sequelize
.
Error
();
var
error
=
new
Sequelize
.
Error
();
var
validationError
=
new
Sequelize
.
ValidationError
();
var
validationError
=
new
Sequelize
.
ValidationError
();
...
@@ -25,10 +24,12 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
...
@@ -25,10 +24,12 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
var
instError
=
new
sequelize
.
Error
();
var
instError
=
new
sequelize
.
Error
();
var
instValidationError
=
new
sequelize
.
ValidationError
();
var
instValidationError
=
new
sequelize
.
ValidationError
();
expect
(
error
).
to
.
be
.
instanceOf
(
Error
)
expect
(
error
).
to
.
be
.
instanceOf
(
Sequelize
.
Error
);
expect
(
validationError
).
to
.
be
.
instanceOf
(
Error
)
expect
(
error
).
to
.
have
.
property
(
'name'
,
'SequelizeBaseError'
);
expect
(
instError
).
to
.
be
.
instanceOf
(
Error
)
expect
(
validationError
).
to
.
be
.
instanceOf
(
Sequelize
.
ValidationError
);
expect
(
instValidationError
).
to
.
be
.
instanceOf
(
Error
)
expect
(
validationError
).
to
.
have
.
property
(
'name'
,
'SequelizeValidationError'
);
expect
(
instError
).
to
.
be
.
instanceOf
(
Sequelize
.
Error
);
expect
(
instValidationError
).
to
.
be
.
instanceOf
(
Sequelize
.
ValidationError
);
})
})
})
})
})
})
;
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