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 398ae593
authored
Aug 29, 2019
by
Bill Li
Committed by
Sushant
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(types): support error with rejectOnEmpty (#11359)
1 parent
47ee5345
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
28 deletions
types/lib/model.d.ts
types/test/errors.ts
types/lib/model.d.ts
View file @
398ae59
...
@@ -569,7 +569,7 @@ export interface NonNullFindOptions extends FindOptions {
...
@@ -569,7 +569,7 @@ export interface NonNullFindOptions extends FindOptions {
/**
/**
* Throw if nothing was found.
* Throw if nothing was found.
*/
*/
rejectOnEmpty
:
boolean
;
rejectOnEmpty
:
boolean
|
Error
;
}
}
/**
/**
...
...
types/test/errors.ts
View file @
398ae59
...
@@ -4,36 +4,55 @@ import { User } from './models/User';
...
@@ -4,36 +4,55 @@ import { User } from './models/User';
import
{
OptimisticLockError
}
from
'../lib/errors'
;
import
{
OptimisticLockError
}
from
'../lib/errors'
;
async
function
test
()
{
async
function
test
()
{
try
{
try
{
await
User
.
create
({
username
:
'john_doe'
});
await
User
.
create
({
username
:
'john_doe'
});
}
catch
(
e
)
{
}
catch
(
e
)
{
if
(
e
instanceof
UniqueConstraintError
)
{
if
(
e
instanceof
UniqueConstraintError
)
{
console
.
error
((
e
as
UniqueConstraintError
).
sql
);
throw
new
Error
((
e
as
UniqueConstraintError
).
sql
);
}
}
}
}
try
{
try
{
await
User
.
findOne
({
await
User
.
findOne
({
rejectOnEmpty
:
true
,
rejectOnEmpty
:
true
,
where
:
{
where
:
{
username
:
'something_that_doesnt_exist'
,
username
:
'something_that_doesnt_exist'
,
},
},
});
});
}
catch
(
e
)
{
}
catch
(
e
)
{
if
(
!
(
e
instanceof
EmptyResultError
))
{
if
(
!
(
e
instanceof
EmptyResultError
))
{
console
.
error
(
'should return emptyresulterror'
);
throw
new
Error
(
'should return emptyresulterror'
);
}
}
}
}
try
{
const
user
:
User
|
null
=
await
User
.
findByPk
(
1
);
class
CustomError
extends
Error
{}
if
(
user
!=
null
)
{
user
.
username
=
'foo'
;
try
{
user
.
save
();
await
User
.
findOne
({
}
rejectOnEmpty
:
new
CustomError
(
'User does not exist'
),
}
catch
(
e
)
{
where
:
{
if
(
!
(
e
instanceof
OptimisticLockError
))
{
username
:
'something_that_doesnt_exist'
,
console
.
log
(
'should return OptimisticLockError'
);
},
}
});
}
catch
(
e
)
{
if
(
!
(
e
instanceof
CustomError
))
{
throw
new
Error
(
'should return CustomError'
);
}
if
(
e
.
message
!==
'User does not exist'
)
{
throw
new
Error
(
'should return CustomError with the proper message'
)
}
}
try
{
const
user
:
User
|
null
=
await
User
.
findByPk
(
1
);
if
(
user
!=
null
)
{
user
.
username
=
'foo'
;
user
.
save
();
}
}
catch
(
e
)
{
if
(
!
(
e
instanceof
OptimisticLockError
))
{
throw
new
Error
(
'should return OptimisticLockError'
);
}
}
}
}
}
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