mirror of
https://github.com/expo/entity.git
synced 2026-11-13 20:28:06 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c692afbcb |
No files matched your search
+18
@@ -1,8 +1,26 @@
|
||||
import { EntityDatabaseAdapterTransientError, EntityErrorState } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { wrapNativePostgresCallAsync } from '../wrapNativePostgresCallAsync.ts';
|
||||
|
||||
describe(wrapNativePostgresCallAsync, () => {
|
||||
it('classifies a PostgreSQL lock timeout as transient and preserves the cause', async () => {
|
||||
const error = Object.assign(new Error('canceling statement due to lock timeout'), {
|
||||
code: '55P03',
|
||||
});
|
||||
const result = wrapNativePostgresCallAsync(async () => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
await expect(result).rejects.toBeInstanceOf(EntityDatabaseAdapterTransientError);
|
||||
await expect(result).rejects.toMatchObject({
|
||||
state: EntityErrorState.TRANSIENT,
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
cause: error,
|
||||
});
|
||||
});
|
||||
|
||||
it('rethrows literals', async () => {
|
||||
const throwingFn = async (): Promise<void> => {
|
||||
// eslint-disable-next-line no-throw-literal,@typescript-eslint/only-throw-error
|
||||
|
||||
@@ -38,6 +38,8 @@ function translatePostgresError(
|
||||
return new EntityDatabaseAdapterCheckConstraintError(error.message, error);
|
||||
case '23P01':
|
||||
return new EntityDatabaseAdapterExclusionConstraintError(error.message, error);
|
||||
case '55P03':
|
||||
return new EntityDatabaseAdapterTransientError(error.message, error);
|
||||
default:
|
||||
return new EntityDatabaseAdapterUnknownError(error.message, error);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user