不要怂,就是干,撸起袖子干!

Commit 398ae593 by Bill Li Committed by Sushant

fix(types): support error with rejectOnEmpty (#11359)

1 parent 47ee5345
Showing with 23 additions and 4 deletions
...@@ -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;
} }
/** /**
......
...@@ -8,7 +8,7 @@ async function test() { ...@@ -8,7 +8,7 @@ async function test() {
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);
} }
} }
...@@ -21,7 +21,26 @@ async function test() { ...@@ -21,7 +21,26 @@ async function test() {
}); });
} catch (e) { } catch (e) {
if (!(e instanceof EmptyResultError)) { if (!(e instanceof EmptyResultError)) {
console.error('should return emptyresulterror'); throw new Error('should return emptyresulterror');
}
}
class CustomError extends Error {}
try {
await User.findOne({
rejectOnEmpty: new CustomError('User does not exist'),
where: {
username: 'something_that_doesnt_exist',
},
});
} 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')
} }
} }
...@@ -33,7 +52,7 @@ async function test() { ...@@ -33,7 +52,7 @@ async function test() {
} }
} catch (e) { } catch (e) {
if (!(e instanceof OptimisticLockError)) { if (!(e instanceof OptimisticLockError)) {
console.log('should return OptimisticLockError'); throw new Error('should return OptimisticLockError');
} }
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!