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

Commit f4a46dc1 by Mirko Jotic Committed by Sushant

fix(typings): add OptimisticLockError type (#10777)

1 parent 380738b8
Showing with 20 additions and 0 deletions
......@@ -130,6 +130,13 @@ export class ExclusionConstraintError extends DatabaseError {
}
/**
* Thrown when attempting to update a stale model instance
*/
export class OptimisticLockError extends BaseError {
constructor(options: { message?: string, modelName?: string, values?: { [key: string]: any }, where?: { [key: string]: any } });
}
/**
* A base class for all connection related errors.
*/
export class ConnectionError extends BaseError {
......
// Error === BaseError
import { BaseError, EmptyResultError, Error, UniqueConstraintError } from 'sequelize';
import { User } from './models/User';
import { OptimisticLockError } from '../lib/errors';
async function test() {
try {
......@@ -23,4 +24,16 @@ async function test() {
console.error('should return emptyresulterror');
}
}
try {
const user: User | null = await User.findByPk(1);
if (user != null) {
user.username = 'foo';
user.save();
}
} catch (e) {
if (!(e instanceof OptimisticLockError)) {
console.log('should return OptimisticLockError');
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!