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 fc644f4b
authored
Oct 27, 2018
by
Pavel
Committed by
Sushant
Oct 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(error): optimistic lock message (#10068)
1 parent
4b39e530
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
lib/errors/index.js
test/integration/error.test.js
lib/errors/index.js
View file @
fc644f4
...
@@ -92,7 +92,7 @@ class OptimisticLockError extends BaseError {
...
@@ -92,7 +92,7 @@ class OptimisticLockError extends BaseError {
constructor
(
options
)
{
constructor
(
options
)
{
options
=
options
||
{};
options
=
options
||
{};
options
.
message
=
options
.
message
||
`Attempting to update a stale model instance:
${
options
.
modelName
}
`
;
options
.
message
=
options
.
message
||
`Attempting to update a stale model instance:
${
options
.
modelName
}
`
;
super
(
options
);
super
(
options
.
message
);
this
.
name
=
'SequelizeOptimisticLockError'
;
this
.
name
=
'SequelizeOptimisticLockError'
;
/**
/**
* The name of the model on which the update was attempted
* The name of the model on which the update was attempted
...
...
test/integration/error.test.js
View file @
fc644f4
...
@@ -242,7 +242,36 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
...
@@ -242,7 +242,36 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), () => {
});
});
});
});
describe
(
'Constraint error'
,
()
=>
{
describe
(
'OptimisticLockError'
,
()
=>
{
it
(
'got correct error type and message'
,
function
()
{
const
Account
=
this
.
sequelize
.
define
(
'Account'
,
{
number
:
{
type
:
Sequelize
.
INTEGER
}
},
{
version
:
true
});
return
Account
.
sync
({
force
:
true
}).
then
(()
=>
{
const
result
=
Account
.
create
({
number
:
1
}).
then
(
accountA
=>
{
return
Account
.
findByPk
(
accountA
.
id
).
then
(
accountB
=>
{
accountA
.
number
+=
1
;
return
accountA
.
save
().
then
(()
=>
{
return
accountB
;
});
});
}).
then
(
accountB
=>
{
accountB
.
number
+=
1
;
return
accountB
.
save
();
});
return
Promise
.
all
([
expect
(
result
).
to
.
eventually
.
be
.
rejectedWith
(
Support
.
Sequelize
.
OptimisticLockError
),
expect
(
result
).
to
.
eventually
.
be
.
rejectedWith
(
'Attempting to update a stale model instance: Account'
)
]);
});
});
});
describe
(
'ConstraintError'
,
()
=>
{
[
[
{
{
type
:
'UniqueConstraintError'
,
type
:
'UniqueConstraintError'
,
...
...
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