@@ -111,9 +111,9 @@ public override int SaveChanges(IList<IUpdateEntry> entries)
111
111
rowsAffected ++ ;
112
112
}
113
113
}
114
- catch ( CosmosException ex )
114
+ catch ( Exception ex ) when ( ex is not DbUpdateException and not OperationCanceledException )
115
115
{
116
- throw ThrowUpdateException ( ex , entry ) ;
116
+ throw WrapUpdateException ( ex , entry ) ;
117
117
}
118
118
}
119
119
@@ -175,9 +175,9 @@ public override async Task<int> SaveChangesAsync(
175
175
rowsAffected ++ ;
176
176
}
177
177
}
178
- catch ( CosmosException ex )
178
+ catch ( Exception ex ) when ( ex is not DbUpdateException and not OperationCanceledException )
179
179
{
180
- throw ThrowUpdateException ( ex , entry ) ;
180
+ throw WrapUpdateException ( ex , entry ) ;
181
181
}
182
182
}
183
183
@@ -378,25 +378,19 @@ private IUpdateEntry GetRootDocument(InternalEntityEntry entry)
378
378
}
379
379
#pragma warning restore EF1001 // Internal EF Core API usage.
380
380
381
- private Exception ThrowUpdateException ( CosmosException exception , IUpdateEntry entry )
381
+ private Exception WrapUpdateException ( Exception exception , IUpdateEntry entry )
382
382
{
383
383
var documentSource = GetDocumentSource ( entry . EntityType ) ;
384
384
var id = documentSource . GetId ( entry . SharedIdentityEntry ?? entry ) ;
385
- throw exception . StatusCode switch
385
+
386
+ return exception switch
386
387
{
387
- HttpStatusCode . PreconditionFailed =>
388
- new DbUpdateConcurrencyException ( CosmosStrings . UpdateConflict ( id ) , exception , new [ ] { entry } ) ,
389
- HttpStatusCode . Conflict =>
390
- new DbUpdateException ( CosmosStrings . UpdateConflict ( id ) , exception , new [ ] { entry } ) ,
391
- _ => Rethrow ( exception ) ,
388
+ CosmosException { StatusCode : HttpStatusCode . PreconditionFailed }
389
+ => new DbUpdateConcurrencyException ( CosmosStrings . UpdateConflict ( id ) , exception , new [ ] { entry } ) ,
390
+ CosmosException { StatusCode : HttpStatusCode . Conflict }
391
+ => new DbUpdateException ( CosmosStrings . UpdateConflict ( id ) , exception , new [ ] { entry } ) ,
392
+ _ => new DbUpdateException ( CosmosStrings . UpdateStoreException ( id ) , exception , new [ ] { entry } )
392
393
} ;
393
394
}
394
-
395
- private static Exception Rethrow ( Exception ex )
396
- {
397
- // Re-throw an exception, preserving the original stack and details, without being in the original "catch" block.
398
- ExceptionDispatchInfo . Capture ( ex ) . Throw ( ) ;
399
- return ex ;
400
- }
401
395
}
402
396
}
0 commit comments