From f234dc11429a0a4d1c1f7df7a5d1dcf732b717b2 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 23 Oct 2023 16:45:49 +0500 Subject: [PATCH] =?UTF-8?q?ParamsNames=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=20ErrorStat?= =?UTF-8?q?e,=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20=20-=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Exceptions/ArgumentInvalidException.cs | 11 +++++------ .../Middlewares/SimplifyExceptionsMiddleware.cs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs index f5e3f3cd..5db63313 100644 --- a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs +++ b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace AsbCloudApp.Exceptions { @@ -9,9 +10,9 @@ namespace AsbCloudApp.Exceptions public class ArgumentInvalidException : Exception { /// - /// название аргумента + /// словарь с ошибками, где ключ - имя аргумента, а значение - массив из одного сообщения /// - public IDictionary ParamsNames { get; } = null!; + public IDictionary ErrorState { get; } = null!; /// /// конструктор @@ -21,7 +22,7 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string paramName, string message) : base(message) { - ParamsNames = new Dictionary() { + ErrorState = new Dictionary() { { paramName, new[]{ message } } }; } @@ -34,9 +35,7 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string[] paramsNames, string message) : base(message) { - ParamsNames = new Dictionary() { - { string.Join(", ", paramsNames), new[]{ message } } - }; + ErrorState = paramsNames.ToDictionary(paramName => paramName, item => new[] { message }); } } } diff --git a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs index 3b3f052a..3c444b4a 100644 --- a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs +++ b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs @@ -56,7 +56,7 @@ namespace AsbCloudWebApi.Middlewares private static string MakeJsonBody(ArgumentInvalidException ex) { - var problem = new ValidationProblemDetails(ex.ParamsNames); + var problem = new ValidationProblemDetails(ex.ErrorState); var buffer = System.Text.Json.JsonSerializer.Serialize(problem); return buffer; }