Skip to content

mapPersistenceError

mapPersistenceError(error, operation): unknown

Defined in: packages/ddd-mikro-orm/src/errors/transient-error.ts:101

Translates persistence-specific transient failures into the neutral application retry signal. Non-transient failures are returned unchanged.

This is the canonical otherwise translator for @MapPersistenceErrors and @PersistedWrite of @cqrs-ddd/core. Because non-transient errors keep their identity, domain errors a repository throws on purpose (ConcurrencyConflictError, EntityNotFoundException) pass through without a re-throw guard.

unknown

The failure raised by the persistence operation.

string

What was being done, for the message, such as `deleting User ${user.id}`.

unknown

A TransientOperationError whose cause is error, or error itself when it is not transient.

@MapPersistenceErrors<[User], User>({
entity: ([user]) => user,
otherwise: (error, user) =>
mapPersistenceError(error, `deleting User ${user.id}`),
})
async save(user: User): Promise<null> { ... }
// Outside the lifecycle decorators:
try {
return await em.findOne(Auth, { refreshTokenHash: hash }, { refresh: true });
} catch (error) {
throw mapPersistenceError(error, 'auth session lookup');
}