Arora.GlobalExceptionHandler
1.0.2
dotnet add package Arora.GlobalExceptionHandler --version 1.0.2
NuGet\Install-Package Arora.GlobalExceptionHandler -Version 1.0.2
<PackageReference Include="Arora.GlobalExceptionHandler" Version="1.0.2" />
<PackageVersion Include="Arora.GlobalExceptionHandler" Version="1.0.2" />
<PackageReference Include="Arora.GlobalExceptionHandler" />
paket add Arora.GlobalExceptionHandler --version 1.0.2
#r "nuget: Arora.GlobalExceptionHandler, 1.0.2"
#:package Arora.GlobalExceptionHandler@1.0.2
#addin nuget:?package=Arora.GlobalExceptionHandler&version=1.0.2
#tool nuget:?package=Arora.GlobalExceptionHandler&version=1.0.2
Arora.GlobalExceptionHandler
Arora.GlobalExceptionHandler is an open-source .NET 8+ class library that provides global exception handling middleware for minimal APIs. It allows you to catch unhandled exceptions across your application in a single try-catch block, making error handling simpler and more consistent.
Why This Library Was Created
In modern web applications, managing errors gracefully is essential for both debugging and providing a good user experience. The typical approach to exception handling involves wrapping each endpoint or request handler in a try-catch block, which can be cumbersome and repetitive.
The idea behind Arora.GlobalExceptionHandler is to centralize exception handling in a single middleware, so that all exceptions�regardless of where they occur�are caught and handled in one place. This simplifies the code, reduces redundancy, and ensures consistent error responses for all unhandled exceptions.
How It Works
This library adds middleware to your WebApplication pipeline that intercepts all requests. When an unhandled exception occurs, the middleware catches it and returns a formatted JSON response with the exception details.
By using this middleware, you ensure that your application always returns a consistent error format, no matter where the exception originates.
Features
- Centralized Error Handling: Catch all exceptions in one
try-catchblock. - JSON Response: Automatically formats error messages in a JSON response.
- Minimal Configuration: Simple and straightforward integration into your application.
Installation
You can add the Arora.GlobalExceptionHandler library to your .NET 8+ class library by referencing the project or package. Ensure that your project targets .NET 8+.
Usage
Step 1: Install the Library
Add Arora.GlobalExceptionHandler to your project by adding the necessary reference in your .csproj file or by using a package manager.
Step 2: Use the Middleware
In your Program.cs or Startup.cs file, call the UseGlobalExceptionHandler extension method to add the middleware to the pipeline.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Arora.GlobalExceptionHandler;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Add global exception handler middleware
app.UseGlobalExceptionHandler();
// Configure your endpoints
app.MapGet("/", () => "Hello World!");
app.Run();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.