Skip to content

Commit

Permalink
Fix Required Service (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Artem Leshchev <[email protected]>
  • Loading branch information
aleshchev and Artem Leshchev authored May 14, 2024
1 parent 9fcb790 commit a1e677b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Bss.Platform.Api.Middlewares/ErrorsMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
using Bss.Platform.Api.Middlewares.Interfaces;

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Bss.Platform.Api.Middlewares;

public class ErrorsMiddleware(RequestDelegate next, ILogger<ErrorsMiddleware> logger, IStatusCodeResolver? statusCodeResolver)
public class ErrorsMiddleware(RequestDelegate next, ILogger<ErrorsMiddleware> logger, IServiceProvider serviceProvider)
{
public async Task Invoke(HttpContext context)
{
Expand All @@ -28,7 +29,8 @@ public async Task Invoke(HttpContext context)
private Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = MediaTypeNames.Application.Json;
context.Response.StatusCode = (int)(statusCodeResolver?.Resolve(exception) ?? HttpStatusCode.InternalServerError);
context.Response.StatusCode =
(int)(serviceProvider.GetService<IStatusCodeResolver>()?.Resolve(exception) ?? HttpStatusCode.InternalServerError);

return context.Response.WriteAsync(JsonSerializer.Serialize(exception.GetBaseException().Message));
}
Expand Down
6 changes: 3 additions & 3 deletions src/__SolutionItems/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyCompany("Luxoft")]
[assembly: AssemblyCopyright("Copyright © Luxoft 2024")]

[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyInformationalVersion("1.3.1.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down

0 comments on commit a1e677b

Please sign in to comment.