public override void OnException(ExceptionContext context) { var notification = new Notification("Ocorreu um erro interno"); var domainNotification = context.HttpContext.RequestServices.GetService(typeof(IDomainNotification)) as IDomainNotification; AppLoggerFactory.GetLogger().Error(context.Exception); if (domainNotification == null) { context.Result = new ObjectResult(EnvelopResult.Fail(new[] { notification })) { StatusCode = 500 }; return; } if (!domainNotification.HasNotifications()) { domainNotification.Handle(notification); } context.Result = new ObjectResult(EnvelopResult.Fail(domainNotification.Notifications)) { StatusCode = 500 }; }
public IActionResult CreatedResponse <T>(T data = default, string url = "") { if (!DomainNotification.HasNotifications()) { return(Created(url, EnvelopDataResult <T> .Ok(data))); } return(BadRequest(EnvelopResult.Fail(DomainNotification.Notify()))); }
public IActionResult CreatedResponse(string url = "") { if (!DomainNotification.HasNotifications()) { return(Created(url, EnvelopResult.Ok())); } return(BadRequest(EnvelopResult.Fail(DomainNotification.Notify()))); }
public IActionResult CreateResponse() { if (!DomainNotification.HasNotifications()) { return(Ok(EnvelopResult.Ok())); } return(BadRequest(EnvelopResult.Fail(DomainNotification.Notify()))); }
public IActionResult NotFoundResponse() { if (DomainNotification.HasNotifications()) { DomainNotification.Dispose(); } DomainNotification.Handle(new Notification("Recurso não encontrado")); return(new NotFoundObjectResult(EnvelopResult.Fail(DomainNotification.Notify()))); }
public IActionResult UnprocessableResponse() { if (DomainNotification.HasNotifications()) { DomainNotification.Dispose(); } DomainNotification.Handle(new Notification("Entidade não processável")); return(UnprocessableEntity(EnvelopResult.Fail(DomainNotification.Notify()))); }
public IActionResult ForbiddenResponse() { if (DomainNotification.HasNotifications()) { DomainNotification.Dispose(); } DomainNotification.Handle(new Notification("Forbidden")); return(new ObjectResult(EnvelopResult.Fail(DomainNotification.Notify())) { StatusCode = 403 }); }
public IActionResult UnauthorizedResponse() { if (DomainNotification.HasNotifications()) { DomainNotification.Dispose(); } DomainNotification.Handle(new Notification("Unauthorized")); return(new ObjectResult(EnvelopResult.Fail(DomainNotification.Notify())) { StatusCode = 401 }); }
public static void ConfigureExceptionHandler(this IApplicationBuilder app) { app.UseExceptionHandler(appError => { appError.Run(async context => { var contextFeature = context.Features.Get <IExceptionHandlerFeature>(); if (contextFeature != null) { if (contextFeature.Error is InvalidOperationException && contextFeature.Error.Message.StartsWith( "The SPA default page middleware could not return the default page")) { return; } context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; EnvelopResult result = null; var notification = new Notification("Ocorreu um erro interno"); var domainNotification = context.RequestServices.GetService(typeof(IDomainNotification)) as IDomainNotification; AppLoggerFactory.GetLogger().Error(contextFeature.Error); if (domainNotification == null) { result = EnvelopResult.Fail(new[] { notification }); } if (domainNotification?.HasNotifications() == false) { domainNotification.Handle(notification); result = EnvelopResult.Fail(domainNotification?.Notifications); } var response = JsonUtils.Serialize(result); await context.Response.WriteAsync(response); } }); }); }