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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user