From 1c004491863590440140ee41925728235061bfd6 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 11 May 2026 14:24:46 +0200 Subject: [PATCH] Improve error handling for problem details deserialization Explicitly catch JsonException and NotSupportedException when reading problem details from HTTP responses. Add comments to clarify that these errors are ignored since problem details are optional, making error handling more precise and avoiding unintended exception swallowing. --- DbFirst.BlazorWebApp/Services/ApiClientHelper.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DbFirst.BlazorWebApp/Services/ApiClientHelper.cs b/DbFirst.BlazorWebApp/Services/ApiClientHelper.cs index 59f323f..458fd6b 100644 --- a/DbFirst.BlazorWebApp/Services/ApiClientHelper.cs +++ b/DbFirst.BlazorWebApp/Services/ApiClientHelper.cs @@ -1,4 +1,5 @@ using System.Net; +using System.Text.Json; namespace DbFirst.BlazorWebApp.Services; @@ -25,7 +26,14 @@ internal static class ApiClientHelper problemDetail = problem.Detail ?? problem.Type; } } - catch { } + catch (JsonException) + { + // Ignoriere Fehler beim Lesen der Problem-Details, da sie optional sind + } + catch (NotSupportedException) + { + // Ignoriere Fehler beim Lesen der Problem-Details, da sie optional sind + } var status = response.StatusCode; var reason = response.ReasonPhrase;