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

View File

@ -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;
}