Skip to main content

Error Handling

Repository methods translate provider-specific failures into a small set of typed exceptions from Wemogy.Core.Errors.Exceptions. This keeps error handling provider-independent: the same catch works whether the repository is backed by Cosmos DB, MongoDB or the in-memory implementation.

ExceptionRaised when
NotFoundErrorExceptionA requested entity does not exist (or is soft-deleted / hidden by a read filter). Thrown by GetAsync, QuerySingleAsync, EnsureExistsAsync and DeleteAsync.
ConflictErrorExceptionCreateAsync is called with an id that already exists.
PreconditionFailedErrorExceptionAn optimistic concurrency check failed (eTag mismatch), or QuerySingleAsync matched more than one entity.
UnexpectedErrorExceptionAn entity is misconfigured (for example a missing [Id] or [PartitionKey] attribute), or another unexpected error occurred.

Example

using Wemogy.Core.Errors.Exceptions;

try
{
var user = await userRepository.GetAsync(id, partitionKey);
}
catch (NotFoundErrorException)
{
// the entity does not exist, was soft-deleted, or is hidden by a read filter
}

Each exception carries a stable error Code (for example EntityNotFound, AlreadyExists, EtagMismatch) and a human-readable message. The not-found message also includes the entity type name and partition key to make debugging easier.

info

ExistsAsync does not throw for a missing entity; it returns false. Use EnsureExistsAsync when you want a NotFoundErrorException instead.