Sitewerk.Exceptions
8.0.0
dotnet add package Sitewerk.Exceptions --version 8.0.0
NuGet\Install-Package Sitewerk.Exceptions -Version 8.0.0
<PackageReference Include="Sitewerk.Exceptions" Version="8.0.0" />
<PackageVersion Include="Sitewerk.Exceptions" Version="8.0.0" />
<PackageReference Include="Sitewerk.Exceptions" />
paket add Sitewerk.Exceptions --version 8.0.0
#r "nuget: Sitewerk.Exceptions, 8.0.0"
#:package Sitewerk.Exceptions@8.0.0
#addin nuget:?package=Sitewerk.Exceptions&version=8.0.0
#tool nuget:?package=Sitewerk.Exceptions&version=8.0.0
Sitewerk.Exceptions
Sitewerk.Exceptions provides a simple, consistent way to create and handle domain-specific exceptions across Sitewerk .NET services. It standardizes:
- A clear exception taxonomy (InvalidData, Forbidden, Conflict, etc.) via dedicated exception types
- A builder pattern to compose exceptions with details, fault duration, and inner exceptions
- Lightweight metadata to aid diagnostics (fault duration, sensitive data flag, details)
This repository contains a single NuGet package built from Sitewerk.Exceptions/.
NuGet package
- Package ID:
Sitewerk.Exceptions - Version:
8.0.0 - Target framework:
net8.0 - Authors: Sitewerk AG
Install
Use any of the following:
# In a project directory
dotnet add package Sitewerk.Exceptions --version 8.0.0
# Or in a Package Manager Console (Visual Studio)
Install-Package Sitewerk.Exceptions -Version 8.0.0
Quick start
Throw a standardized exception using the builder API:
using Sitewerk.Exceptions;
// Example: invalid data that is permanent and should not be retried
throw new ExceptionBuilder()
.IsPermanent()
.HasInvalidData()
.AddDetail("CustomerService", "Email address format is invalid.")
.AddDetail("CustomerService", "Allowed domains: example.com, example.org.")
.Build();
Catch and handle by specific type or by the common base type:
try
{
ProcessCustomer(customer);
}
catch (InvalidDataException ex)
{
// Specific handling for invalid data
LogValidationIssues(ex.Details);
}
catch (SitewerkException ex)
{
// Generic handling for Sitewerk exceptions
if (ex.FaultDuration == FaultDuration.Transient)
{
// Consider retrying
}
if (ex.HasInnerException)
{
// Inspect ex.InnerException
}
}
Exception model
Core primitives:
SitewerkException(base class)FaultDuration FaultDuration— Unknown | Transient | PermanentIReadOnlyList<ExceptionDetail> Details— optional key-value like details (Source,Message)Exception? InnerException— optional inner exceptionbool HasSensitiveData— indicates details may contain sensitive info (hide in client responses)
ExceptionBuilder— fluent API to construct the correct exception type based on anErrorReasonandFaultDuration.ErrorReason— classification used by the builder: NotDefined, Unknown, Forbidden, Unauthenticated, InvalidDataStructure, InvalidData, MissingData, Conflict, UnreachableSystem, UnsupportedAcceptFormat, UnsupportedContentType, VirusDetected.ExceptionDetail— a record withSourceandMessagefor diagnostics.FaultDuration— Unknown | Transient | Permanent (guides retry strategies).
Concrete exception types provided (all derive from SitewerkException):
DataConflictExceptionForbiddenExceptionInvalidDataExceptionInvalidDataStructureExceptionMissingDataExceptionUnknownExceptionUnreachableSystemExceptionUnsupportedAcceptFormatExceptionUnsupportedContentTypeExceptionVirusDetectedException
Builder reference
Common builder methods:
- Duration:
.IsTransient(),.IsPermanent() - Reasons:
.HasInvalidData(),.HasInvalidDataStructure(),.HasMissingData(),.HasDataConflict(),.HasInvalidAccessRight()(Forbidden),.CannotCommunicateWithOtherSystem()(Unreachable),.HasUnsupportedAcceptFormat(),.HasUnsupportedContentType(),.HasVirusDetected() - Details:
.AddDetail(source, message),.AddDetail(ExceptionDetail),.AddDetails(collection) - Inner:
.AddException(Exception) - Sensitivity:
.HasSensitiveExceptionData() - Finalize:
.Build()→ returns the correct concreteSitewerkException
Usage patterns and guidance
- Prefer throwing specific types via the builder so consumers can
catchby type. - Set
FaultDurationto guide retry logic (e.g., transient network hiccups vs. permanent validation failures). - Use
ExceptionDetailto aggregate multiple validation or diagnostic messages. KeepSourcemeaningful (e.g., component or field name). - If details may contain secrets or PII, call
.HasSensitiveExceptionData()and ensure downstream layers omit those details from client-facing responses.
Build and pack locally (optional)
You can build and pack the NuGet locally:
# Build the solution
dotnet build c:\Repo\framework-sw-projects\exceptions\Sitewerk.Exceptions.sln -c Release
# Pack the project to produce the .nupkg (bin/Release)
dotnet pack c:\Repo\framework-sw-projects\exceptions\Sitewerk.Exceptions\Sitewerk.Exceptions.csproj -c Release
The package icon is embedded from assets/sitewerk-logo.png. License acceptance is not required (PackageRequireLicenseAcceptance=false).
Versioning
The package version is 8.0.0 (aligned with .NET 8). Follow semantic versioning when publishing updates.
| 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 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. |
-
net8.0
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Sitewerk.Exceptions:
| Package | Downloads |
|---|---|
|
Sitewerk.Security.Cors
Package Description |
|
|
Sitewerk.Api.Middleware.ExceptionHandler
Package Description |
|
|
Sitewerk.DataAccess.WebService
Package Description |
|
|
Sitewerk.FluentValidation
Validation framework based on FluentValidation |
|
|
Sitewerk.Data.Base
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial version