Catch general exception for all db types (#6846)

* Switch `SqlException` to `DbException`

Co-authored-by: rkac-bw <148072202+rkac-bw@users.noreply.github.com>

* Fix CA2253

---------

Co-authored-by: rkac-bw <148072202+rkac-bw@users.noreply.github.com>
This commit is contained in:
Justin Baur
2026-01-14 16:27:39 -05:00
committed by GitHub
parent fa845a4753
commit 584af2ee3f

View File

@@ -1,5 +1,5 @@
using Bit.Core.Utilities; using System.Data.Common;
using Microsoft.Data.SqlClient; using Bit.Core.Utilities;
namespace Bit.Admin.HostedServices; namespace Bit.Admin.HostedServices;
@@ -30,7 +30,7 @@ public class DatabaseMigrationHostedService : IHostedService, IDisposable
// TODO: Maybe flip a flag somewhere to indicate migration is complete?? // TODO: Maybe flip a flag somewhere to indicate migration is complete??
break; break;
} }
catch (SqlException e) catch (DbException e)
{ {
if (i >= maxMigrationAttempts) if (i >= maxMigrationAttempts)
{ {
@@ -40,7 +40,7 @@ public class DatabaseMigrationHostedService : IHostedService, IDisposable
else else
{ {
_logger.LogError(e, _logger.LogError(e,
"Database unavailable for migration. Trying again (attempt #{0})...", i + 1); "Database unavailable for migration. Trying again (attempt #{AttemptNumber})...", i + 1);
await Task.Delay(20000, cancellationToken); await Task.Delay(20000, cancellationToken);
} }
} }