Код: Выделить всё
public class TaskHTTP_ClientClient
{
private readonly HttpClient httpClient = new HttpClient();
private readonly JsonSerializerOptions serializerOptions = new() { PropertyNamingPolicy = null };
public override async System.Threading.Tasks.Task RetrieveSelection(
TaskGateway.SelectionRetrieving.RequestParameters requestParameters
)
{
HttpResponseMessage response = await this.httpClient.GetAsync(/* */);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync();
}
throw new Exception("Failed to retrieve tasks selection.", response.StatusCode);
}
}
Код: Выделить всё
public class TaskHTTP_ClientClient
{
private readonly HttpClient httpClient = new HttpClient();
private readonly JsonSerializerOptions serializerOptions = new() { PropertyNamingPolicy = null };
public override async System.Threading.Tasks.Task RetrieveSelection(
TaskGateway.SelectionRetrieving.RequestParameters requestParameters
)
{
HttpResponseMessage response = await this.httpClient.GetAsync(/* */);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync();
}
string errorData = await response.Content.ReadAsStringAsync();
throw new Exception(errorData);
}
}

System.Exception: {"type":"https://tools.ietf.org/html/rfc9110#sec ... "Произошла одна или несколько ошибок проверки.","status":400,"errors":{"optionalFiltering":["Необязательное поле Filtering требуется."]},"traceId":"00-7612a7eb6ea01309ea7dd827171dea35-1486e2e916e49364-00"
at Client.Data.FromServer.TaskHTTP_ClientGateway.RetrieveSelection(RequestParameters requestParameters)
в Client.SharedState.TasksSharedState.retrieveTasksSelection(Options options)
Почему бы не украсить данные об ошибках?
Код: Выделить всё
public class TaskHTTP_ClientClient
{
private readonly HttpClient httpClient = new HttpClient();
private readonly JsonSerializerOptions serializerOptions = new() { PropertyNamingPolicy = null };
public override async System.Threading.Tasks.Task RetrieveSelection(
TaskGateway.SelectionRetrieving.RequestParameters requestParameters
)
{
HttpResponseMessage response = await this.httpClient.GetAsync(/* */);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync();
}
object errorData = await response.Content.ReadFromJsonAsync();
throw new Exception(
System.Text.Json.JsonSerializer.Serialize(
errorData,
options: new System.Text.Json.JsonSerializerOptions
{
WriteIndented = true
}
)
);
}
}

Теперь мы можем мгновенно узнать причину ошибки.
Я делаю что-то не так?
Подробнее здесь: https://stackoverflow.com/questions/798 ... nation-whe
Мобильная версия