net6conversion (#642)

* Converting to net6 startup and integration test formats

* Update to minimal api and using pagetitle

* Adjust functional test fixtures
Update ApiEndpoints package version

* Finish migration to minimal api startup
This commit is contained in:
Steve Smith
2021-12-06 15:14:43 -05:00
committed by GitHub
parent 20b060aeb3
commit ce63e38a23
34 changed files with 499 additions and 728 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Net;
using System.Threading.Tasks;
using BlazorShared.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.eShopWeb.ApplicationCore.Exceptions;
namespace Microsoft.eShopWeb.PublicApi.Middleware;
public class ExceptionMiddleware
{
private readonly RequestDelegate _next;
public ExceptionMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext httpContext)
{
try
{
await _next(httpContext);
}
catch (Exception ex)
{
await HandleExceptionAsync(httpContext, ex);
}
}
private async Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = "application/json";
if (exception is DuplicateException duplicationException)
{
context.Response.StatusCode = (int)HttpStatusCode.Conflict;
await context.Response.WriteAsync(new ErrorDetails()
{
StatusCode = context.Response.StatusCode,
Message = duplicationException.Message
}.ToString());
}
}
}