private Task HandleExceptionAsync(HttpContext context, Exception exception, ILoggerInterface loggerInterface) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; loggerInterface.LogToDb(new ExceptionViewModel { ExceptionMsg = exception.Message, ExceptionSource = exception.Source, ExceptionType = exception.GetType().ToString(), ExceptionURL = exception.StackTrace.ToString() }); return(context.Response.WriteAsync(new { context.Response.StatusCode, Message = "Internal Server Error from the custom middleware." }.ToString())); }