public ApiException(ExceptionsTypes ErrorCode, ModelStateDictionary modelState, ViewModelBase viewModel = null, HttpStatusCode?statusCode = null) : base(ErrorCode, "Model State Invalid") { Setup(); this.StatusCode = (statusCode == null) ? (int)HttpStatusCode.BadRequest : (int)statusCode; this.Errors = ModelStateDictionaryToString(modelState); this.Validations = (viewModel == null) ? null: viewModel.Validations; }
public ApiException(ExceptionsTypes ErrorCode, IEnumerable <IdentityError> errors, HttpStatusCode?statusCode = null) : base(ErrorCode, "Identity Error") { Setup(); this.StatusCode = (statusCode == null) ? (int)HttpStatusCode.BadRequest : (int)statusCode; this.Errors = errors.Select(a => $"Error: {a.Code} - {a.Description}").ToList(); this.Validations = null; }
public BaseException(ExceptionsTypes ErrorCode, string Message) : base(String.Format("{0} ({1})", Message, GetDescription(ErrorCode))) { ExceptionType = ErrorCode; if (ExceptionType == ExceptionsTypes.DatabaseError || ExceptionType == ExceptionsTypes.SystemError) { StatusCode = (int)HttpStatusCode.InternalServerError; } }
public ApiException(ExceptionsTypes ErrorCode, Exception ex, HttpStatusCode?statusCode = null) : base(ExceptionErrorCode(ex, ErrorCode), ExceptionErrorToString(ex)) { Setup(); this.StatusCode = (statusCode == null) ? (int)HttpStatusCode.BadRequest : (int)statusCode; this.Errors = new List <string> { ExceptionErrorToString(ex) }; this.Validations = null; }
public ApiException(ExceptionsTypes ErrorCode, string message, HttpStatusCode?statusCode = null) : base(ErrorCode, message) { Setup(); this.StatusCode = (statusCode == null) ? (int)HttpStatusCode.BadRequest : (int)statusCode; this.Errors = new List <string> { message }; this.Validations = null; }
public static ExceptionsTypes ExceptionErrorCode(Exception ex, ExceptionsTypes ErrorCode) { if (ex is DbUpdateException) { return(ExceptionsTypes.DatabaseError); } else if (ex is Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException) { return(ExceptionsTypes.DatabaseError); } return(ErrorCode); }
private static void ExceptionsSection() { start: Console.WriteLine("\t\t\tВыберите раздел: \n" + "1. Обработка исключений.Конструкция try..catch..finally\n" + "2. Catch. Фильтры исключения When\n" + "3. Типы исключений. Класс Exception"); select: Console.WriteLine($"{line}{line}{line}"); Console.Write(HelpText); string selection = Console.ReadLine(); Console.Clear(); switch (selection) { case HelpCode: goto start; case ExecuteCode: ExecuteApp(); break; case ChapterCode: ChooseChapter(); break; case "1": Console.WriteLine(line + typeof(ExceptionsConstruction).Name.ToString() + line); ExceptionsConstruction.Action(); goto select; case "2": Console.WriteLine(line + typeof(ExceptionsFilters).Name.ToString() + line); ExceptionsFilters.Action(); goto select; case "3": Console.WriteLine(line + typeof(ExceptionsTypes).Name.ToString() + line); ExceptionsTypes.Action(); goto select; default: Console.WriteLine(ErrorText); goto select; } }