private async Task HandleExceptionAsync(HttpContext context, Exception exception) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.OK; //context.Request.Path; ExceptionLog exceptionLog = new ExceptionLog() { date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), exception = exception, message = exception.Message, ipAddress = context.Connection.RemoteIpAddress.ToString() }; #if !DEBUG exceptionLogService.AddExceptionLog(exceptionLog); #endif resultObject resultObject = new resultObject(); var splitPathInfo = context.Request.Path.Value.Split("/"); resultObject.serverErrors.Add(new ServerError() { hint = exception.Message, type = ConstErrorTypes.ServerError, controllerName = splitPathInfo[2], stackTrace = exception.StackTrace }); await context.Response.WriteAsync(Newtonsoft.Json.JsonConvert.SerializeObject(resultObject)); }