RSPLGlobalExceptionHandler 1.2.0

dotnet add package RSPLGlobalExceptionHandler --version 1.2.0                
NuGet\Install-Package RSPLGlobalExceptionHandler -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RSPLGlobalExceptionHandler" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RSPLGlobalExceptionHandler --version 1.2.0                
#r "nuget: RSPLGlobalExceptionHandler, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RSPLGlobalExceptionHandler as a Cake Addin
#addin nuget:?package=RSPLGlobalExceptionHandler&version=1.2.0

// Install RSPLGlobalExceptionHandler as a Cake Tool
#tool nuget:?package=RSPLGlobalExceptionHandler&version=1.2.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

alternate text is missing from this package README image

Getting Started:

To integrate the Exception Middleware into your ASP.NET Core application, follow these steps:

  1. Add the Middleware to Your Project: Copy the ExceptionMiddleware.cs file into your project's middleware directory.
  2. Register the Middleware: In your Program.cs file, add the following line within the Configure method to register the Exception Middleware:

alternate text is missing from this package README image

  1. 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:

alternate text is missing from this package README image

  • 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:

  1. Add the ProcessResponse Class: Copy the ProcessResponse.cs file into your project's middleware or utility directory.
  2. Usage in Exception Handling: Within your exception handling logic, utilize the ProcessResponse.Create method to generate an HTTP response with the appropriate error details.

alternate text is missing from this package README image

  1. 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:

alternate text is missing from this package README image

**Supported Parameters πŸ˜—*

The ProcessResponse.Create method supports the following parameters:

alternate text is missing from this package README image

  • 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:

  1. Reference the ResponseMessage Class: Ensure that the ResponseMessage.cs file is included in your project's utility or common directory.
  2. Usage in Success Scenarios: Utilize the predefined success messages from the ResponseMessage class to provide feedback to users in various success scenarios.

alternate text is missing from this package README image

  1. 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:

alternate text is missing from this package README image

**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.

alternate text is missing from this package README image

**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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.0 91 4/3/2024