Skip to content

Commit

Permalink
fix(typings): add OptimisticLockError type (#10777)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkojotic authored and sushantdhiman committed Apr 16, 2019
1 parent 380738b commit f4a46dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions types/lib/errors.d.ts
Expand Up @@ -129,6 +129,13 @@ export class ExclusionConstraintError extends DatabaseError {
constructor(options: { parent?: Error; message?: string; constraint?: string; fields?: string[]; table?: string });
}

/**
* 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.
*/
Expand Down
13 changes: 13 additions & 0 deletions types/test/errors.ts
@@ -1,6 +1,7 @@
// Error === BaseError
import { BaseError, EmptyResultError, Error, UniqueConstraintError } from 'sequelize';
import { User } from './models/User';
import { OptimisticLockError } from '../lib/errors';

async function test() {
try {
Expand All @@ -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');
}
}
}

0 comments on commit f4a46dc

Please sign in to comment.