Utility library for handling Problem Details error responses in .NET applications.
Install-Package Jimmys20.ProblemDetails
...
using Jimmys20.ProblemDetails;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddTransient<ProblemDetailsHandler>();
builder.Services
.AddHttpClient("ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<ProblemDetailsHandler>();
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("ServerAPI"));
await builder.Build().RunAsync();
...
@using Jimmys20.ProblemDetails
...
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
try
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
}
catch (ProblemDetailsException ex)
{
var problem = ex.Problem;
}
}
}