ParamsNames переименован в ErrorState, правка по ревью - 3

This commit is contained in:
Olga Nemt 2023-10-23 16:45:49 +05:00
parent 01765d05ec
commit f234dc1142
2 changed files with 6 additions and 7 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace AsbCloudApp.Exceptions namespace AsbCloudApp.Exceptions
{ {
@ -9,9 +10,9 @@ namespace AsbCloudApp.Exceptions
public class ArgumentInvalidException : Exception public class ArgumentInvalidException : Exception
{ {
/// <summary> /// <summary>
/// название аргумента /// словарь с ошибками, где ключ - имя аргумента, а значение - массив из одного сообщения
/// </summary> /// </summary>
public IDictionary<string, string[]> ParamsNames { get; } = null!; public IDictionary<string, string[]> ErrorState { get; } = null!;
/// <summary> /// <summary>
/// конструктор /// конструктор
@ -21,7 +22,7 @@ namespace AsbCloudApp.Exceptions
public ArgumentInvalidException(string paramName, string message) public ArgumentInvalidException(string paramName, string message)
: base(message) : base(message)
{ {
ParamsNames = new Dictionary<string, string[]>() { ErrorState = new Dictionary<string, string[]>() {
{ paramName, new[]{ message } } { paramName, new[]{ message } }
}; };
} }
@ -34,9 +35,7 @@ namespace AsbCloudApp.Exceptions
public ArgumentInvalidException(string[] paramsNames, string message) public ArgumentInvalidException(string[] paramsNames, string message)
: base(message) : base(message)
{ {
ParamsNames = new Dictionary<string, string[]>() { ErrorState = paramsNames.ToDictionary(paramName => paramName, item => new[] { message });
{ string.Join(", ", paramsNames), new[]{ message } }
};
} }
} }
} }

View File

@ -56,7 +56,7 @@ namespace AsbCloudWebApi.Middlewares
private static string MakeJsonBody(ArgumentInvalidException ex) 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); var buffer = System.Text.Json.JsonSerializer.Serialize(problem);
return buffer; return buffer;
} }