private Either <DomainError, IImmutableList <string> > Mapper(IEnumerable <TitlesStorage> source) { try { if (!source.Any()) { return(ImmutableList <string> .Empty); } var item = source.Single(); if (item == null || string.IsNullOrWhiteSpace(item.Titles)) { return(BasicError.Create(nameof(FeedTitlesRepository), "Title source contains more than one record")); } return(item .Titles .Split(',') .Select(x => x.Trim()) .ToImmutableList()); } catch (Exception e) { return(ExceptionError.FromException(e)); } }
private IActionResult ToActionResult(OperationResult result) { if (result.IsValid) { return(Ok()); } OperationError firstError = result.Errors.FirstOrDefault(); if (firstError == null) { return(BadRequest(new BasicError("An unknown error occured"))); } var errorDescription = new BasicError(firstError.Description); switch (firstError.Type) { case OperationError.ErrorType.General: return(BadRequest(errorDescription)); case OperationError.ErrorType.NotFound: return(NotFound(errorDescription)); case OperationError.ErrorType.ProcessingError: return(StatusCode(500, errorDescription)); default: throw new ArgumentOutOfRangeException($"Unexpected [{typeof(OperationError.ErrorType).Name}] enum value"); } }
public static IActionResult ToActionResult(this DomainError error, ILogger log) { return(error switch { ExceptionError eError => eError.ToActionResult(log), ValidationErrors vError => vError.ToActionResult(log), NotFoundError nError => nError.ToActionResult(log), BasicError bError => bError.ToActionResult(log), _ => new InternalServerErrorResult() });
/// <summary> /// add error message with low priority /// </summary> /// <param name="msg">set your message.</param> /// <param name="quantityTypeIsNotValidPleaseSelectAValidQuantityType"></param> public int Add(string msg, string solution = "", string link = "", string linkTitle = "") { var error = new BasicError { OrderId = _orderIncrementer++, ErrorMessage = msg, Type = ErrorType.Low }; _errors.Add(error); return(error.OrderId); }
/// <summary> /// add error message with medium priority /// </summary> /// <param name="msg">set your message.</param> public int AddMedium(string msg) { var error = new BasicError() { OrderID = orderIncrementer++, Message = msg, Type = ErrorType.Medium }; errors.Add(error); return(error.OrderID); }
/// <summary> /// add error message with low priority /// </summary> /// <param name="msg">set your message.</param> /// <param name="quantityTypeIsNotValidPleaseSelectAValidQuantityType"></param> public int Add(string msg, string quantityTypeIsNotValidPleaseSelectAValidQuantityType) { var error = new BasicError() { OrderID = orderIncrementer++, Message = msg, Type = ErrorType.Low }; errors.Add(error); return(error.OrderID); }
/// <summary> /// add error message with given priority /// </summary> /// <param name="msg">set your message.</param> /// <param name="type">Type of your error message.</param> public int Add(string msg, ErrorType type) { var error = new BasicError() { OrderID = orderIncrementer++, Message = msg, Type = type }; errors.Add(error); return(error.OrderID); }
/// <summary> /// add error message with high priority /// </summary> /// <param name="msg">set your message.</param> public int AddHigh(string msg, string solution = "", string link = "", string linkTitle = "") { var error = new BasicError { Type = ErrorType.High, OrderId = _orderIncrementer++, ErrorMessage = msg, Solution = solution, Link = link, LinkTitle = linkTitle }; _errors.Add(error); return(error.OrderId); }
private BasicError GetNewBasicError(string msg, ErrorType type, string cssClass = "", string solution = "", string link = "", string linkTitle = "") { var error = new BasicError { Type = type, OrderId = _orderIncrementer++, ErrorMessage = msg, Solution = solution, SolutionLink = link, SolutionDisplayMessage = linkTitle, CssClass = cssClass }; return(error); }
public string GetCssForError(BasicError e) { if (e.Type == ErrorType.High) { return(HighRisk); } if (e.Type == ErrorType.Medium) { return(MidRisk); } if (e.Type == ErrorType.Low) { return(LowRisk); } return(LowRisk); }
/// <summary> /// Get cssClass class names /// </summary> /// <param name="e"></param> /// <returns> /// By default : /// High : label label-danger high-priority /// Medium : label label-danger medium-priority /// low : label label-warning low-priority /// </returns> public string GetCssClassForError(BasicError e) { if (!string.IsNullOrEmpty(e.CssClass)) { return(e.CssClass); } if (e.Type == ErrorType.High) { return(HighRiskCssClass); } if (e.Type == ErrorType.Medium) { return(MidRiskCssClass); } if (e.Type == ErrorType.Low) { return(LowRiskCssClass); } return(LowRiskCssClass); }