Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Concurrent;
using System.Net;
using System.Net.Http;
using System.ServiceModel;
using System.Xml;
using static Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Communication;

Expand Down Expand Up @@ -308,6 +309,12 @@ private static void HandleException(ConnectorBase connector, Settings settings,
{
httpStatusCode = HttpStatusCode.OK;
Comment thread
MatthiasSort marked this conversation as resolved.
bool skipError = false;
//Do not mark the connection as failed when the ERP itself returned a fault (business error), report it as 500 like the Endpoint path does
if (IsErpBusinessFault(ex))
{
httpStatusCode = HttpStatusCode.InternalServerError;
skipError = true;
}
//Do not ping Endpoints with Internal Server Error 500 (that means that the request was received but generating response failed)
if (ex?.InnerException is not null)
{
Expand Down Expand Up @@ -355,6 +362,54 @@ private static void HandleException(ConnectorBase connector, Settings settings,
}
}

/// <summary>
/// Determines whether the exception is a fault returned by the ERP itself (e.g. a NAV/BC business error),
/// as opposed to a failure of the connector service or of its connection to the ERP.
/// </summary>
private static bool IsErpBusinessFault(Exception ex)
{
for (var current = ex; current is not null; current = current.InnerException)
{
//Connector service internal error with exception details (DebugInfo=True in the connector service config)
if (current is FaultException<ExceptionDetail> detailFault)
{
return IsErpInternalServerError(detailFault.Detail);
}
//Fault passed through from the ERP, or connector service internal error without exception details
if (current is FaultException fault)
{
return !IsInternalServiceFault(fault.Code);
}
}
return false;
}

private static bool IsInternalServiceFault(FaultCode code)
{
for (var current = code; current is not null; current = current.SubCode)
{
if (string.Equals(current.Name, "InternalServiceFault", StringComparison.Ordinal))
{
return true;
}
}
return false;
}

private static bool IsErpInternalServerError(ExceptionDetail detail)
{
//The connector service received an HTTP 500 response from the ERP (e.g. a SOAP fault from the BC OAuth endpoint)
for (var current = detail; current is not null; current = current.InnerException)
{
if (string.Equals(current.Type, typeof(WebException).FullName, StringComparison.Ordinal) &&
!string.IsNullOrEmpty(current.Message) && current.Message.Contains("(500)"))
{
return true;
}
}
return false;
}

/// <summary>
/// Retrieves a PDF document as a Base64-encoded string based on the specified request and submission type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.21.9</Version>
<Version>10.21.10</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Live Integration</Title>
<Description>Live Integration</Description>
Expand Down Expand Up @@ -28,6 +28,7 @@
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.21.5" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.21.5" />
<PackageReference Include="Dynamicweb.Ecommerce.UI" Version="10.21.5" />
<PackageReference Include="System.ServiceModel.Primitives" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
Loading