Akash.Gavali
1.0.0
RSPLGlobalExceptionHandler 1.2.0
Additional DetailsUse RSPLGlobalExceptionHandler 1.2.0 for same
dotnet add package Akash.Gavali --version 1.0.0
NuGet\Install-Package Akash.Gavali -Version 1.0.0
<PackageReference Include="Akash.Gavali" Version="1.0.0" />
paket add Akash.Gavali --version 1.0.0
#r "nuget: Akash.Gavali, 1.0.0"
// Install Akash.Gavali as a Cake Addin #addin nuget:?package=Akash.Gavali&version=1.0.0 // Install Akash.Gavali as a Cake Tool #tool nuget:?package=Akash.Gavali&version=1.0.0
Exception Middleware Usage Guide
1. Using Custom Exception Middleware
Introduction:
The Exception Middleware provided in this repository is a utility for handling exceptions in ASP.NET Core applications. This middleware intercepts exceptions that occur during the execution of HTTP requests and generates appropriate HTTP responses with error details.
Exception middleware is an important aspect of the error handling mechanism in .NET Core applications. It is a piece of code that is executed whenever an exception is thrown in the application, providing a way to handle the exception and gracefully recover from it.
**About Middleware π*
.NET Core middleware refers to a component that handles requests and responses in the pipeline of an ASP.NET Core application. Middleware functions are organized into a pipeline where each component chooses whether to pass the request on to the next component in the pipeline, or to complete the request by generating a response.
Middleware can be used to perform tasks such as authentication, caching, and logging. It can also be used to modify the request and response, or to short-circuit the request pipeline and return a response directly.
.NET Core middleware is easy to write and allows for a high degree of customization and flexibility in the handling of requests and responses in an ASP.NET Core application. Hereβs an illustration from the official documentation
Getting Started:
To integrate the Exception Middleware into your ASP.NET Core application, follow these steps:
- Add the Middleware to Your Project: Copy the ExceptionMiddleware.cs file into your project's middleware directory.
- Register the Middleware: In your Program.cs file, add the following line within the Configure method to register the Exception Middleware:
- Customize Exception Handling: You can customize the handling of different types of exceptions by modifying the HandleExceptionAsync method in the ExceptionMiddleware.cs file. Each exception type is mapped to a specific HTTP status code and error message.
Exception Handling:
The Exception Middleware provides default handling for several common types of exceptions, such as ArgumentException, FileNotFoundException, SqlException, etc. Each type of exception is associated with an appropriate HTTP status code and error message.
You can also extend the middleware to handle additional exception types or customize the error responses according to your application's requirements.
Examples:
Here are some examples of how the Exception Middleware handles different types of exceptions:
- ArgumentException: Returns a 400 Bad Request status code with the message "One or more arguments provided are not valid."
- FileNotFoundException or DirectoryNotFoundException: Returns a 404 Not Found status code with the message "File or directory not found."
- SqlException: Returns a 500 Internal Server Error status code with the message "Error in SQL Server."
- AggregateException: Recursively handles each inner exception within the AggregateException.
2. Using ProcessResponse Class for Exception Handling
Introduction:
The ProcessResponse class provided in this repository is a utility for generating HTTP responses with error details. It encapsulates the creation of an HTTP response object with the provided result, message, and status code.
Getting Started:
To integrate the ProcessResponse class into your ASP.NET Core application for handling exceptions and generating HTTP responses, follow these steps:
- Add the ProcessResponse Class: Copy the ProcessResponse.cs file into your project's middleware or utility directory.
- Usage in Exception Handling: Within your exception handling logic, utilize the ProcessResponse.Create method to generate an HTTP response with the appropriate error details.
- Customize Error Handling: You can customize the error handling logic and the HTTP response generated by modifying the parameters passed to the ProcessResponse.Create method.
Example Usage:
Here's an example of how you can utilize the ProcessResponse class method within your exception handling logic:
**Supported Parameters π*
The ProcessResponse.Create method supports the following parameters:
- result: The exception object or result data to include in the response.
- message: The message to include in the response.
- statusCode (optional): The HTTP status code of the response. Default is OK (200).
**Customization π*
You can customize the HTTP response generated by modifying the parameters passed to the ProcessResponse.Create method. This allows you to tailor the error response according to your application's requirements.
3. Using ResponseMessage Class for Success Messages
**Introduction π*
The ResponseMessage class provided in this repository contains predefined success messages that can be utilized to provide feedback to users in your ASP.NET Core application.
**Getting Started π*
To integrate the ResponseMessage class into your application for providing success messages, follow these steps:
- Reference the ResponseMessage Class: Ensure that the ResponseMessage.cs file is included in your project's utility or common directory.
- Usage in Success Scenarios: Utilize the predefined success messages from the ResponseMessage class to provide feedback to users in various success scenarios.
- Customization: You can customize the success messages according to your application's requirements by modifying the constants defined in the ResponseMessage class.
**Example Usage π*
Here's an example of how you can utilize the ResponseMessage class to provide a success message in your code:
**Supported Success Messages π*
The ResponseMessage class provides predefined success messages for various scenarios, such as saving, copying, deleting, updating records, uploading files, sending emails, and more.
**Customization π*
You can customize the success messages provided by the ResponseMessage class to better suit your application's context and requirements. Modify the constants in the ResponseMessage class as needed.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net7.0
- Microsoft.AspNetCore.Diagnostics.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Data.SqlClient (>= 5.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.0 | 111 | 4/3/2024 |