mirror of https://github.com/Squidex/squidex.git
7 changed files with 106 additions and 24 deletions
@ -0,0 +1,30 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Log; |
|||
|
|||
namespace Squidex.Web.Pipeline |
|||
{ |
|||
public class DefaultExceptionHandler : IExceptionHandler |
|||
{ |
|||
private readonly ISemanticLog log; |
|||
|
|||
public DefaultExceptionHandler(ISemanticLog log) |
|||
{ |
|||
Guard.NotNull(log); |
|||
|
|||
this.log = log; |
|||
} |
|||
|
|||
public void Handle(Exception ex) |
|||
{ |
|||
log.LogError(ex, w => w.WriteProperty("status", "UnhandledException")); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
|
|||
namespace Squidex.Web.Pipeline |
|||
{ |
|||
public interface IExceptionHandler |
|||
{ |
|||
void Handle(Exception exception); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Log; |
|||
using Squidex.Infrastructure.Security; |
|||
|
|||
namespace Squidex.Web.Pipeline |
|||
{ |
|||
public sealed class RequestExceptionMiddleware : IMiddleware |
|||
{ |
|||
private readonly IExceptionHandler exceptionHandler; |
|||
|
|||
public RequestExceptionMiddleware(IExceptionHandler exceptionHandler) |
|||
{ |
|||
Guard.NotNull(exceptionHandler); |
|||
|
|||
this.exceptionHandler = exceptionHandler; |
|||
} |
|||
|
|||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
|||
{ |
|||
try |
|||
{ |
|||
await next(context); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
exceptionHandler.Handle(ex); |
|||
|
|||
context.Response.StatusCode = 500; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue