Do you also have a solution for now?
I am try to do something like this:
try
{
// MAKE UPDATE
}
catch (MongoDuplicateKeyException ex)
{
ThrowDuplicateException(ex, EntityUpdateExceptionReason.UniqueFailed, ex.WriteConcernResult != null ? ex.WriteConcernResult.LastErrorMessage : "-");
}
catch (MongoWriteConcernException ex)
{
ThrowException(ex, EntityUpdateExceptionReason.Undefined, ex.WriteConcernResult != null ? ex.WriteConcernResult.LastErrorMessage : "-");
}
catch (MongoWriteException ex)
{
ThrowException(ex, EntityUpdateExceptionReason.Undefined, ex.WriteConcernError != null ? ex.WriteConcernError.Message : "-");
}
catch (MongoBulkWriteException ex)
{
string writeErrors = ex.WriteErrors != null ? string.Join(", ", ex.WriteErrors.Select(x => x.Message)) : "-";
ThrowException(ex, EntityUpdateExceptionReason.Undefined, writeErrors);
}
catch (Exception ex)
{
throw new EntityUpdateException(EntityUpdateExceptionReason.Undefined, ex.Message, ex);
}
}
private static void ThrowDuplicateException(Exception ex, EntityUpdateExceptionReason reason, string writeError)
{
string message = string.Format(CultureInfo.InvariantCulture, "An entity with the same unique constraints already exists. MongoDB Error: {0}, Exception message: {1}", writeError, ex.Message);
throw new EntityUpdateException(reason, message, ex);
}
private static void ThrowException(Exception ex, EntityUpdateExceptionReason reason, string writeError)
{
string message = string.Format(CultureInfo.InvariantCulture, "Failed to update the entity. MongoDB Error: {0}, Exception message: {1}", writeError, ex.Message);
throw new EntityUpdateException(reason, message, ex);
}
But the Error message is often "-" because I dont know the right properties and exceptions to catch.