Skip to content

Jimmys20/ProblemDetails

Repository files navigation

ProblemDetails NuGet

Utility library for handling Problem Details error responses in .NET applications.

Installation

Install-Package Jimmys20.ProblemDetails

Usage

Blazor

Program.cs

...
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();

_Imports.razor

...
@using Jimmys20.ProblemDetails

FetchData.razor

...

@code {
    private WeatherForecast[]? forecasts;
    
    protected override async Task OnInitializedAsync()
    {
        try
        {
            forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
        }
        catch (ProblemDetailsException ex)
        {
            var problem = ex.Problem;
        }
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages