Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(errorHandling): adjust general error handler #130

Merged
merged 1 commit into from
Feb 13, 2025
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 @@ -21,5 +21,5 @@ namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess;

public interface IRegistryRepositories
{
public T GetInstance<T>();
T GetInstance<T>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="3.7.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="3.7.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Linq" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Logging" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess" Version="3.7.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Linq" Version="3.7.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Logging" Version="3.7.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding" Version="3.7.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using Json.Schema;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.ErrorHandling;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.Models;
using System.Reflection;
using System.Text.Json;
Expand All @@ -32,7 +33,7 @@ public async Task<bool> Validate(CredentialSchemaType? schemaType, JsonDocument
var location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (location == null)
{
throw new UnexpectedConditionException("Assembly location must be set");
throw UnexpectedConditionException.Create(ErrorTypes.ASSEMBLY_LOCATION_NOT_SET);
}

if (schemaType is not null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using System.Collections.Immutable;

namespace Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.ErrorHandling;

public class ErrorMessageContainer : IErrorMessageContainer
{
private static readonly IReadOnlyDictionary<int, string> Messages = ImmutableDictionary.CreateRange<int, string>([
new((int)ErrorTypes.ASSEMBLY_LOCATION_NOT_SET, "Assembly location must be set")
]);

public Type Type { get => typeof(ErrorTypes); }
public IReadOnlyDictionary<int, string> MessageContainer { get => Messages; }
}

public enum ErrorTypes
{
ASSEMBLY_LOCATION_NOT_SET
}
7 changes: 7 additions & 0 deletions src/registry/SsiAuthoritySchemaRegistry.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Web;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Web;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.DependencyInjection;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.Controllers;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.ErrorHandling;
using System.Text.Json.Serialization;

var version = AssemblyExtension.GetApplicationVersion();
Expand All @@ -29,6 +32,9 @@ await WebApplicationBuildRunner
.BuildAndRunWebApplicationAsync<Program>(args, "registry", version, ".Registry",
builder =>
{
builder.Services.AddSingleton<IErrorMessageContainer, ErrorMessageContainer>();
builder.Services.AddSingleton<IErrorMessageService, ErrorMessageService>();
builder.Services.AddTransient<GeneralHttpExceptionMiddleware>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddRegistryRepositories(builder.Configuration);
builder.Services.ConfigureHttpJsonOptions(options =>
Expand All @@ -42,6 +48,7 @@ await WebApplicationBuildRunner
},
(app, _) =>
{
app.UseMiddleware<GeneralHttpExceptionMiddleware>();
app.MapGroup("/api")
.WithOpenApi()
.MapRegistryApi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="JsonSchema.Net" Version="7.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Web" Version="3.3.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Web" Version="3.7.0" />
<PackageReference Include="System.Json" Version="4.8.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<PackageReference Include="FakeItEasy" Version="8.3.0" />
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider" Version="3.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.9.3" />
Expand Down
Loading