diff --git a/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs b/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs index ef942e99e..366cd2b1e 100644 --- a/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs +++ b/starsky/starsky.foundation.database/Thumbnails/ThumbnailQuery.cs @@ -283,7 +283,7 @@ private async Task SaveChangesDuplicate(DbContext dbContext) catch ( Exception exception ) { // Check if the inner exception is a MySqlException - var mySqlException = exception as MySqlException; + var mySqlException = exception.InnerException as MySqlException; // Skip if Duplicate entry // MySqlConnector.MySqlException (0x80004005): Duplicate entry for key 'PRIMARY' // https://github.com/qdraw/starsky/issues/1248 https://github.com/qdraw/starsky/issues/1489 @@ -299,7 +299,8 @@ private async Task SaveChangesDuplicate(DbContext dbContext) _logger.LogError($"[SaveChangesDuplicate] T:{exception.GetType()} " + $"M:{exception.Message} " + $"I: {exception.InnerException} " + - $"ErrorCode: {mySqlException?.ErrorCode}"); + $"IM: {mySqlException?.Message} " + + $"IM ErrorCode: {mySqlException?.ErrorCode}"); throw; } diff --git a/starsky/starskytest/starsky.foundation.database/Thumbnails/ThumbnailQueryErrorTest.cs b/starsky/starskytest/starsky.foundation.database/Thumbnails/ThumbnailQueryErrorTest.cs index 7c0b7a92e..6ac77eab4 100644 --- a/starsky/starskytest/starsky.foundation.database/Thumbnails/ThumbnailQueryErrorTest.cs +++ b/starsky/starskytest/starsky.foundation.database/Thumbnails/ThumbnailQueryErrorTest.cs @@ -108,8 +108,7 @@ public async Task AddThumbnailRangeAsync_SomethingElseShould_ExpectedException() new FakeIWebLogger(), new FakeMemoryCache() ); - // Assert that a MySqlException is thrown when AddThumbnailRangeAsync is called - await Assert.ThrowsExceptionAsync(async () => + await Assert.ThrowsExceptionAsync(async () => await fakeQuery.AddThumbnailRangeAsync([new ThumbnailResultDataTransferModel("t")])); } @@ -252,7 +251,7 @@ public MySqlSaveDbExceptionContext(DbContextOptions options, string error, public override Task SaveChangesAsync(CancellationToken cancellationToken = default) { IsCalledMySqlSaveDbExceptionContext = true; - throw CreateMySqlException(_error, _key); + throw new DbUpdateException("dbUpdate", CreateMySqlException(_error, _key)); } [SuppressMessage("Usage",