Skip to content

Commit

Permalink
Improved handling of errors from elastic tables
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Feb 11, 2024
1 parent 42df033 commit d4717f0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/QueryExecutionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public QueryExecutionException(string message, Exception innerException) : base(
}
else if (innerException is FaultException<OrganizationServiceFault> faultEx)
{
Errors = new[] { new Sql4CdsError(16, FaultCodeToSqlError(faultEx.Detail.ErrorCode), message) };
Errors = new[] { new Sql4CdsError(16, FaultCodeToSqlError(faultEx.Detail), message) };
}
else if (innerException is AggregateException aggregateException)
{
Expand All @@ -38,7 +38,7 @@ public QueryExecutionException(string message, Exception innerException) : base(
if (innerEx is ISql4CdsErrorException innerSqlEx)
errors.AddRange(innerSqlEx.Errors);
else if (innerEx is FaultException<OrganizationServiceFault> innerFaultEx)
errors.Add(new Sql4CdsError(16, FaultCodeToSqlError(innerFaultEx.Detail.ErrorCode), innerFaultEx.Message));
errors.Add(new Sql4CdsError(16, FaultCodeToSqlError(innerFaultEx.Detail), innerFaultEx.Message));
else
errors.Add(new Sql4CdsError(16, 10337, innerEx.Message));
}
Expand Down Expand Up @@ -68,9 +68,9 @@ public QueryExecutionException(Sql4CdsError error, Exception innerException) : t

public IReadOnlyList<Sql4CdsError> Errors { get; }

private static int FaultCodeToSqlError(int faultCode)
private static int FaultCodeToSqlError(OrganizationServiceFault fault)
{
switch (faultCode)
switch (fault.ErrorCode)
{
case -2147204288: return 8152;
case -2147217098: return 8115;
Expand All @@ -90,10 +90,20 @@ private static int FaultCodeToSqlError(int faultCode)
case -2147213282:
case -2147086332:
case -2147187954: return 547;
case 409: // Elastic tables use HTTP status codes instead of the standard web service error codes
case -2147220937: return 2627;
}

default: return 10337;
if (fault.ErrorDetails.TryGetValue("ApiExceptionHttpStatusCode", out var httpStatusCode) &&
httpStatusCode is int httpError)
{
switch (httpError)
{
case 409: return 2627;
}
}

return 10337;
}
}
}

0 comments on commit d4717f0

Please sign in to comment.