Pandatech.ResponseCrafter 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pandatech.ResponseCrafter --version 1.0.2
                    
NuGet\Install-Package Pandatech.ResponseCrafter -Version 1.0.2
                    
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="Pandatech.ResponseCrafter" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pandatech.ResponseCrafter" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Pandatech.ResponseCrafter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pandatech.ResponseCrafter --version 1.0.2
                    
#r "nuget: Pandatech.ResponseCrafter, 1.0.2"
                    
#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.
#:package Pandatech.ResponseCrafter@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pandatech.ResponseCrafter&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Pandatech.ResponseCrafter&version=1.0.2
                    
Install as a Cake Tool

Pandatech.ResponseCrafter

Introduction

ResponseCrafter is a comprehensive NuGet package for .NET 8+, specifically designed for enhanced exception handling and logging in ASP.NET applications. This package simplifies the process of handling standard and custom exceptions by crafting detailed error responses suitable for both development and production environments.

Features

  • Custom Exception Handling: Streamlines the process of managing both standard HTTP exceptions and custom exceptions.
  • Detailed Error Responses: Generates verbose error messages, including stack traces for in-depth debugging in development environments.
  • Environment-Sensitive Logging: Offers a class PandaExceptionHandler which can be configured for message verbosity. In production environments, only the exception type and message are logged. In development environments, the entire exception is logged, including the stack trace.
  • Frontend-Friendly Error Messages: Encourages the use of snake_case in error messages, facilitating easier integration with frontend localization systems.
  • Organized/Readable and standardized error responses: Provides a standardized error response format for all exceptions, making it easier for frontend applications to parse and display error messages. The error response format is shown below:
{
  "TraceId": "0HMVFE0A284AM:00000001",
  "Instance": "POST - 164.54.144.23:443/users/register",
  "StatusCode": 400,
  "Type": "BadRequestException",
  "Errors": {
    "email": "email_address_is_not_in_a_valid_format",
    "password": "password_must_be_at_least_8_characters_long"
  },
  "Message": "the_request_was_invalid_or_cannot_be_otherwise_served."
}

Installation

Install the package via NuGet Package Manager or use the following command:

Install-Package ResponseCrafter

Usage

1. Setup Exception Handlers:

Add AddResponseCrafter in program.cs and in configuration set "ResponseCrafterVisibility" to "Public" or "Private".

builder.AddResponseCrafter();
{
  "ResponseCrafterVisibility": "Public"
}

2. Define Custom Exceptions:

  • Create a custom exception class that inherits from ApiException or use already created ones:

  • Utilize ErrorDetails records for specific error messages related to API requests.

3. Configure Middleware:

  • Implement the exception handling middleware in your application's pipeline.
app.UseResponseCrafter();

4. Logging and Error Responses:

  • Automatically logs warnings or errors and provides crafted responses base on the exception type.

Custom Exception Already Created

  • BadRequestException
  • UnauthorizedException
  • PaymentRequiredException
  • ForbiddenException
  • NotFoundException
  • ConflictException
  • TooManyRequestsException
  • InternalServerErrorException
  • ServiceUnavailableException

Recommendations

  • Error Message Formatting: It's recommended to use snake_case for error messages to aid frontend applications in implementing localization.

Limitations

  • This package is specifically tailored for .NET 8 and above.

License

Pandatech.ResponseCrafter is licensed under the MIT License.

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

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pandatech.ResponseCrafter:

Package Downloads
Pandatech.SharedKernel

Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.2.2 206 9/8/2025
5.2.1 165 9/8/2025
5.2.0 153 8/15/2025
5.1.12 244 8/7/2025
5.1.11 138 7/30/2025
5.1.10 263 6/1/2025
5.1.9 238 4/9/2025
5.1.8 217 2/18/2025
5.1.7 180 2/17/2025
5.1.6 175 2/5/2025
5.1.5 170 1/10/2025
5.1.4 134 1/9/2025
5.1.3 183 12/18/2024
5.1.2 165 12/17/2024
5.1.1 190 12/13/2024
5.1.0 159 12/11/2024
5.0.3 173 11/28/2024
5.0.2 202 11/23/2024
5.0.1 207 11/21/2024
5.0.0 154 11/21/2024
4.0.1 180 11/11/2024
4.0.0 182 10/4/2024
3.0.1 222 9/11/2024
3.0.0 193 7/18/2024
2.2.2 188 6/29/2024
2.2.1 183 6/29/2024
2.2.0 186 6/27/2024
2.1.4 191 6/27/2024
2.1.3 222 6/22/2024
2.1.2 160 6/22/2024
2.1.1 174 6/22/2024
2.1.0 168 6/22/2024
2.0.0 180 6/13/2024
1.7.0 165 6/13/2024
1.6.3 172 6/9/2024
1.6.2 187 6/6/2024
1.6.1 195 6/2/2024
1.5.1 190 5/28/2024
1.5.0 181 5/26/2024
1.4.14 185 5/24/2024
1.4.13 168 5/24/2024
1.4.12 195 5/17/2024
1.4.10 195 5/8/2024
1.4.9 198 5/7/2024
1.4.8 179 5/6/2024
1.4.7 192 5/5/2024
1.4.6 153 5/3/2024
1.4.5 185 4/24/2024
1.4.4 179 4/24/2024
1.4.3 177 4/24/2024
1.4.2 180 4/23/2024
1.4.1 198 4/16/2024
1.4.0 202 4/16/2024
1.3.0 174 4/16/2024
1.2.1 212 4/3/2024
1.2.0 212 4/2/2024
1.1.0 241 3/22/2024
1.0.4 548 12/14/2023
1.0.3 221 11/29/2023
1.0.2 209 11/29/2023
1.0.1 216 11/28/2023
1.0.0 226 11/28/2023

Structure change