public async Task <BaseResponseModelPost> Create(AppErrorModel request) { BaseResponseModelPost response = new BaseResponseModelPost(); AppError appError = new AppError { Deleted = false, Exception = request.Exception ?? UNKNOWN, Function = request.Function ?? UNKNOWN, InnerException = request.InnerException ?? UNKNOWN, Message = request.Message ?? UNKNOWN, Module = request.Module ?? UNKNOWN, Solved = false, Time = request.Time ?? DateTime.Now, AppInfo = request.AppInfo ?? UNKNOWN }; await Database.AppError.AddAsync(appError); await Database.SaveChangesAsync(); response.Id = appError.Id; response.Message = "App error was successfully created!"; return(response); }
/// <summary> /// ulozi chybu do db, pokud zapsani do DB selze, zasle mail s chybou na email dany dle DB /// </summary> /// <param name="value">prijaty objekt, obsahujici info o chybe</param> /// <param name="exceptionRound">opakovany zapis chyby po vyjimce</param> /// <returns>objekt s informaci o vysledku</returns> public async Task <BaseResponseModel> SaveErrorToDB(AppErrorModel value, int exceptionRound = 1) { BaseResponseModel model = new BaseResponseModel(); try { await _appErrorService.Create(value); } catch (Exception e) { model.Success = false; model.Message = "Error wasn't processed."; if (exceptionRound < 3) //spadne to 3x? tak do emailu a pokud ani to nepujde, tak do souboru { await SaveErrorToDB(value, exceptionRound + 1); } else { await _emailService.SendEmail("Error occured at logging to DB", $"Exception with log:{Environment.NewLine}\n{e.ParseException()}{Environment.NewLine}\nOriginal exception (JSON):{Environment.NewLine}\n{JsonConvert.SerializeObject(value)}", await _settingService.GetSettingValue(ErrorEmailScope, ErrorEmailName)); } } return(model); }
public async Task Invoke(HttpContext context) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error; if (ex == null) { return; } // // Log _logger.Error(ex); // // Convert to model var error = new AppErrorModel(ex.Message, _env.IsDevelopment() ? ex.StackTrace : null); // // Return exception message as JSON error.Message = ex switch { AppException appException when !string.IsNullOrEmpty(appException.Message) => appException .GetErrorMessages(), { } exception when !string.IsNullOrEmpty(exception.Message) => "Something Bad Happened", _ => error.Message }; // // Return as json context.Response.ContentType = "application/json"; await using var writer = new StreamWriter(context.Response.Body); new CamelCaseJsonSerializer().Serialize(writer, error); await writer.FlushAsync().ConfigureAwait(false); } }
public async Task Invoke(HttpContext context) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; // Find and hold onto any CORS related headers ... var corsHeaders = new HeaderDictionary(); foreach (var pair in context.Response.Headers) { if (!pair.Key.ToLower().StartsWith("access-control-")) { continue; } // Not CORS related corsHeaders[pair.Key] = pair.Value; } var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error; if (ex == null) { return; } var headers = context.Response.Headers; // Ensure all CORS headers remain or else add them back in ... foreach (var pair in corsHeaders) { if (headers.ContainsKey(pair.Key)) { continue; } // Still there! headers.Add(pair.Key, pair.Value); } // // Log _logger.Error(ex); // // Convert to model var error = new AppErrorModel(ex.Message, _env.IsDevelopment() ? ex.StackTrace : null, context.Response.StatusCode); // // Return as json context.Response.ContentType = "application/json; charset=utf-8"; using (var writer = new StreamWriter(context.Response.Body)) { var jsonSerializer = new JsonSerializer { ContractResolver = new CamelCasePropertyNamesContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore, DateTimeZoneHandling = DateTimeZoneHandling.Local, Formatting = Formatting.Indented, DateFormatString = "MM/dd/yy H:mm:ss zzz" }; jsonSerializer.Serialize(writer, error); await writer.FlushAsync().ConfigureAwait(false); } }
/// <summary> /// vytvori error primo z chyby /// </summary> /// <param name="model">objekt reprezentujici chybu</param> /// <returns>objekt s informaci o zpracovani</returns> public async Task <BaseResponseModel> CreateError(AppErrorModel model) { BaseResponseModel result = new BaseResponseModel(); model.AppInfo = $"JazzMetrics - {Configuration["Version"]} -> {model.AppInfo}"; await PostToAPI(SerializeObjectToJSON(model), async (httpResult) => { result = JsonConvert.DeserializeObject <BaseResponseModel>(await httpResult.Content.ReadAsStringAsync()); }); return(result); }
public Task <BaseResponseModel> Edit(AppErrorModel request) { throw new NotImplementedException(); }
public async Task <ActionResult <BaseResponseModel> > Post([FromBody] AppErrorModel value) { return(await HelperService.SaveErrorToDB(value)); }