From ecf870dcba378ab06e2e5623208937e03c8aff8a Mon Sep 17 00:00:00 2001 From: Christo du Toit Date: Tue, 20 Feb 2024 17:38:18 +0000 Subject: [PATCH] CODE RUB: Extended exceptions to take an inner exception --- .../Models/Exceptions/DuplicateKeyException.cs | 3 +++ .../DuplicateKeyWithUniqueIndexException.cs | 12 ++++++++++++ .../ForeignKeyConstraintConflictException.cs | 4 ++++ .../Models/Exceptions/InvalidColumnNameException.cs | 2 ++ .../Models/Exceptions/InvalidObjectNameException.cs | 2 ++ 5 files changed, 23 insertions(+) diff --git a/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyException.cs b/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyException.cs index db7a62f..dc4beeb 100644 --- a/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyException.cs +++ b/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyException.cs @@ -2,6 +2,7 @@ // Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System; using Microsoft.EntityFrameworkCore; namespace STX.EFxceptions.Abstractions.Models.Exceptions @@ -9,5 +10,7 @@ namespace STX.EFxceptions.Abstractions.Models.Exceptions public class DuplicateKeyException : DbUpdateException { public DuplicateKeyException(string message) : base(message) { } + + public DuplicateKeyException(string message, Exception innerException) : base(message, innerException) { } } } diff --git a/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyWithUniqueIndexException.cs b/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyWithUniqueIndexException.cs index fe875be..f95d93b 100644 --- a/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyWithUniqueIndexException.cs +++ b/STX.EFxceptions.Abstractions/Models/Exceptions/DuplicateKeyWithUniqueIndexException.cs @@ -2,6 +2,7 @@ // Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System; using Microsoft.EntityFrameworkCore; namespace STX.EFxceptions.Abstractions.Models.Exceptions @@ -20,5 +21,16 @@ public DuplicateKeyWithUniqueIndexException(string message) DuplicateKeyValue = subStrings[1]; } } + + public DuplicateKeyWithUniqueIndexException(string message, Exception innerException) + : base(message, innerException) + { + string[] subStrings = message.Split('(', ')'); + + if (subStrings.Length == 3) + { + DuplicateKeyValue = subStrings[1]; + } + } } } diff --git a/STX.EFxceptions.Abstractions/Models/Exceptions/ForeignKeyConstraintConflictException.cs b/STX.EFxceptions.Abstractions/Models/Exceptions/ForeignKeyConstraintConflictException.cs index cd56e0f..4ce6166 100644 --- a/STX.EFxceptions.Abstractions/Models/Exceptions/ForeignKeyConstraintConflictException.cs +++ b/STX.EFxceptions.Abstractions/Models/Exceptions/ForeignKeyConstraintConflictException.cs @@ -2,6 +2,7 @@ // Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System; using Microsoft.EntityFrameworkCore; namespace STX.EFxceptions.Abstractions.Models.Exceptions @@ -9,5 +10,8 @@ namespace STX.EFxceptions.Abstractions.Models.Exceptions public class ForeignKeyConstraintConflictException : DbUpdateException { public ForeignKeyConstraintConflictException(string message) : base(message) { } + + public ForeignKeyConstraintConflictException(string message, Exception innerException) + : base(message, innerException) { } } } diff --git a/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidColumnNameException.cs b/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidColumnNameException.cs index 4633c06..45ed525 100644 --- a/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidColumnNameException.cs +++ b/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidColumnNameException.cs @@ -2,6 +2,7 @@ // Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System; using Microsoft.EntityFrameworkCore; namespace STX.EFxceptions.Abstractions.Models.Exceptions @@ -9,5 +10,6 @@ namespace STX.EFxceptions.Abstractions.Models.Exceptions public class InvalidColumnNameException : DbUpdateException { public InvalidColumnNameException(string message) : base(message) { } + public InvalidColumnNameException(string message, Exception innerException) : base(message, innerException) { } } } diff --git a/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidObjectNameException.cs b/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidObjectNameException.cs index b0a1dc0..d38ff74 100644 --- a/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidObjectNameException.cs +++ b/STX.EFxceptions.Abstractions/Models/Exceptions/InvalidObjectNameException.cs @@ -2,6 +2,7 @@ // Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System; using Microsoft.EntityFrameworkCore; namespace STX.EFxceptions.Abstractions.Models.Exceptions @@ -9,5 +10,6 @@ namespace STX.EFxceptions.Abstractions.Models.Exceptions public class InvalidObjectNameException : DbUpdateException { public InvalidObjectNameException(string message) : base(message) { } + public InvalidObjectNameException(string message, Exception innerException) : base(message, innerException) { } } }