Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ExceptionMiddlewareExtensions.cs 1.2KB

123456789101112131415161718192021222324252627282930
  1. using Microsoft.AspNetCore.Diagnostics;
  2. using System.Net;
  3. namespace BlackRock.Reporting.API.Exceptions
  4. {
  5. public static class ExceptionMiddlewareExtensions
  6. {
  7. public static void ConfigureExceptionHandler(this IApplicationBuilder app, ILoggingBuilder logger)
  8. {
  9. app.UseExceptionHandler(appError =>
  10. {
  11. appError.Run(async context =>
  12. {
  13. context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
  14. context.Response.ContentType = "application/json";
  15. var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
  16. if (contextFeature != null)
  17. {
  18. //logger.LogError($"Something went wrong: {contextFeature.Error}");
  19. await context.Response.WriteAsync(new Error()
  20. {
  21. StatusCode = (HttpStatusCode)context.Response.StatusCode,
  22. Title = "Internal Server Error from Custom MiidleWare"
  23. }.ToString());
  24. }
  25. });
  26. });
  27. }
  28. }
  29. }