Skip to content

Commit

Permalink
[ADD] CDP-Error-Tag in http response header; fixes #363
Browse files Browse the repository at this point in the history
* [ADD] CDPErrorTag in http response header
* Refactor error tags to follow existing flows
* Bump SDK version to 27.1.0
  • Loading branch information
lxatstariongroup authored Jul 2, 2024
1 parent 321a68b commit 86772e6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CDP4Orm/CDP4Orm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CDP4JsonSerializer-CE" Version="27.0.2" />
<PackageReference Include="CDP4JsonSerializer-CE" Version="27.1.0" />
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CometServer/CometServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Carter" Version="8.2.1" />
<PackageReference Include="CDP4MessagePackSerializer-CE" Version="27.0.2" />
<PackageReference Include="CDP4ServicesMessaging-CE" Version="27.0.2" />
<PackageReference Include="CDP4MessagePackSerializer-CE" Version="27.1.0" />
<PackageReference Include="CDP4ServicesMessaging-CE" Version="27.1.0" />
<PackageReference Include="FluentValidation" Version="11.9.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
Expand Down
19 changes: 19 additions & 0 deletions CometServer/Modules/10-25/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,5 +1047,24 @@ protected CometTask CreateAndRegisterCometTask(Guid actor, string topContainerNa

return cometTask;
}

/// <summary>
/// Adds a specific CDP error tag to an <see cref="HttpResponse"/> message
/// </summary>
/// <param name="httpResponse">The <see cref="HttpResponse"/></param>
/// <param name="errorTag">The the Error tag</param>
protected void AddErrorTagHeader(HttpResponse httpResponse, string errorTag)
{
var errorTagHeader = HttpConstants.CDPErrorTag;

if (!httpResponse.Headers.ContainsKey(errorTagHeader))
{
httpResponse.Headers[errorTagHeader] = errorTag;
}
else
{
httpResponse.Headers.TryAdd(errorTagHeader, errorTag);
}
}
}
}
4 changes: 3 additions & 1 deletion CometServer/Modules/10-25/EngineeringModelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,9 @@ protected async Task PostResponseData(PostRequestData postRequestData, string re

if (!IsPostAllowedOnIterationSetup(resourceProcessor, iteration))
{
throw new Cdp4ModelValidationException($"It is not allowed to write data to a Frozen {nameof(IterationSetup)}, or its full containment tree. (#FROZEN_ITERATION).");
this.AddErrorTagHeader(httpResponse, "#FROZEN_ITERATION");

throw new Cdp4ModelValidationException($"It is not allowed to write data to a Frozen {nameof(IterationSetup)}, or its full containment tree.");
}

credentialsService.Credentials.Iteration = iteration;
Expand Down
5 changes: 5 additions & 0 deletions CometServer/Services/Headers/HttpConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public static class HttpConstants
/// </summary>
public static readonly string AcceptCdpVersionHeader = "Accept-CDP";

/// <summary>
/// The header that specifies the the error tag of an http response message
/// </summary>
public static readonly string CDPErrorTag = "CDP-Error-Tag";

/// <summary>
/// The default data model version.
/// </summary>
Expand Down

0 comments on commit 86772e6

Please sign in to comment.