develop #10

Merged
s426229 merged 80 commits from develop into master 2021-01-27 18:32:19 +01:00
2 changed files with 42 additions and 1 deletions
Showing only changes of commit 11f96f9d06 - Show all commits

View File

@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace Serwer.Api.Framework
{
public class ExceptionHandlerMiddleware
{
private readonly RequestDelegate _next;
public ExceptionHandlerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
var statusCode = HttpStatusCode.BadRequest;
context.Response.StatusCode = (int)statusCode;
return context.Response.WriteAsync($"Error: {exception.Message}");
}
}
}

View File

@ -15,6 +15,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Serwer.Api.Framework;
using Serwer.Core.Repositories; using Serwer.Core.Repositories;
using Serwer.Infrastructure.Mappers; using Serwer.Infrastructure.Mappers;
using Serwer.Infrastructure.Repositories; using Serwer.Infrastructure.Repositories;
@ -88,7 +89,9 @@ namespace Serwer.Api
} }
app.UseRouting(); app.UseRouting();
app.UseAuthentication(); app.UseMiddleware(typeof(ExceptionHandlerMiddleware));
app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>