Refactor SQL exception handling and config structure

Simplify SQL exception tracking by replacing error message mappings
with a list of relevant error numbers in appsettings.json. Remove
custom error message logic and related classes, introducing
SqlExceptionOptions to hold tracked error codes.
This commit is contained in:
Developer 02
2026-01-22 01:45:50 +01:00
parent ed7237c8dd
commit 22bb585f60
4 changed files with 8 additions and 89 deletions

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Options;
public class SqlExceptionOptions
{
public HashSet<int> SqlExceptionNumber { get; set; } = [];
}

View File

@@ -1,24 +0,0 @@
namespace ReC.Application.Common.Options;
public class SqlExceptionTranslatorOptions
{
public HashSet<int> ErrorNumbers { get; private set; } = [];
private Dictionary<int, string> _badRequestMessages = new()
{
[515] = "{Operation} '{Target}' failed because a required field was not provided or was null. Verify mandatory values and retry.",
[547] = "{Operation} '{Target}' failed because one or more referenced entities do not exist or violate relational rules. Please verify identifiers and constraints.",
[2601] = "{Operation} '{Target}' failed because the data conflicts with a unique constraint. Remove duplicate values and retry.",
[2627] = "{Operation} '{Target}' failed because the data conflicts with a unique constraint. Remove duplicate values and retry."
};
public Dictionary<int, string> ErrorMessages
{
get => _badRequestMessages;
set
{
_badRequestMessages = value;
ErrorNumbers = [.. value.Keys];
}
}
}