Code: Select all
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);
}
}
Code: Select all
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#section-15.5.1", "title": "Ein oder mehrere Validierungsfehler sind aufgetreten.", "status":400, "errors":{"optionalFiltering":["Das optionalFiltering-Feld ist erforderlich."]},"traceId":"00-7612a7eb6ea01309ea7dd827171dea35-1486e2e916e49364-00"
at Client.Data.FromServer.TaskHTTP_ClientGateway.RetrieveSelection(RequestParameters requestParameters)
at Client.SharedState.TasksSharedState.retrieveTasksSelection(Options Optionen)
Warum nicht die Fehlerdaten verschönern?
Code: Select all
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
}
)
);
}
}

Jetzt können wir die Fehlerursache sofort erkennen.
Mache ich etwas falsch?
Mobile version