diff --git a/src/Functions/Altinn.Platform.Authorization.Functions.csproj b/src/Functions/Altinn.Platform.Authorization.Functions.csproj index f49fb33d..aed87375 100644 --- a/src/Functions/Altinn.Platform.Authorization.Functions.csproj +++ b/src/Functions/Altinn.Platform.Authorization.Functions.csproj @@ -1,4 +1,4 @@ - + net6.0 v4 @@ -14,7 +14,7 @@ - + diff --git a/src/Functions/Exceptions/BridgeRequestFailedException.cs b/src/Functions/Exceptions/BridgeRequestFailedException.cs index af2f7c44..a55875ce 100644 --- a/src/Functions/Exceptions/BridgeRequestFailedException.cs +++ b/src/Functions/Exceptions/BridgeRequestFailedException.cs @@ -1,10 +1,47 @@ using System; +using System.Runtime.Serialization; namespace Altinn.Platform.Authorization.Functions.Exceptions; /// /// Generic exception used to trigger re-queueing of messages /// +[Serializable] public class BridgeRequestFailedException : Exception { + /// + /// Initializes a new instance of the class. + /// + public BridgeRequestFailedException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Error message + public BridgeRequestFailedException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Error message + /// Inner exception + public BridgeRequestFailedException(string message, Exception innerException) + : base(message, innerException) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Serialization info + /// Context + protected BridgeRequestFailedException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } } diff --git a/src/Functions/Services/EventPusherService.cs b/src/Functions/Services/EventPusherService.cs index 5abcc342..bafeca02 100644 --- a/src/Functions/Services/EventPusherService.cs +++ b/src/Functions/Services/EventPusherService.cs @@ -43,7 +43,7 @@ public async Task PushEvents(DelegationChangeEventList delegationChangeEventList if (delegationChangeEventList == null) { _logger.LogError("Received null instead of delegation change events. Failed to deserialize model?"); - throw new BridgeRequestFailedException(); + throw new BridgeRequestFailedException("Received null instead of delegation change events. Failed to deserialize model?"); } delegationChangeEventList.DelegationChangeEvents ??= new List(); @@ -75,7 +75,7 @@ await response.Content.ReadAsStringAsync(), GetChangeIdsForLog(delegationChangeEventList)); // Throw exception to ensure requeue of the event list - throw new BridgeRequestFailedException(); + throw new BridgeRequestFailedException($"Bridge returned non-success. resultCode={response.StatusCode} reasonPhrase={response.ReasonPhrase} resultBody={await response.Content.ReadAsStringAsync()} numEventsSent={delegationChangeEventList.DelegationChangeEvents.Count} changeIds={GetChangeIdsForLog(delegationChangeEventList)}"); } if (_logger.IsEnabled(LogLevel.Debug)) @@ -99,7 +99,7 @@ await response.Content.ReadAsStringAsync(), delegationChangeEventList?.DelegationChangeEvents?.Count, GetChangeIdsForLog(delegationChangeEventList)); - throw new BridgeRequestFailedException(); + throw new BridgeRequestFailedException($"Exception thrown while attempting to post delegation events to Bridge. exception={ex.GetType().Name} message={ex.Message} numEventsSent={delegationChangeEventList?.DelegationChangeEvents?.Count} changeIds={GetChangeIdsForLog(delegationChangeEventList)}", ex); } }