Skip to content

Commit b529d36

Browse files
authored
Merge pull request #12 from /issues/10-Include-a-README-and-a-LICENSE-in-the-NuGet-Package
Include a readme and a license in the NuGet package
2 parents 065b98e + e067ba4 commit b529d36

File tree

5 files changed

+39
-40
lines changed

5 files changed

+39
-40
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 ForEvolve
3+
Copyright (c) 2024 Carl-Hugo Marcotte
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,15 @@
55
[![feedz.io](https://img.shields.io/badge/endpoint.svg?url=https%3A%2F%2Ff.feedz.io%2Fforevolve%2Fexception-mapper%2Fshield%2FForEvolve.ExceptionMapper%2Flatest)](https://f.feedz.io/forevolve/exception-mapper/packages/ForEvolve.ExceptionMapper/latest/download)
66

77
A simple ASP.NET Core middleware that intercepts and reacts to `Exception`.
8-
You can map specific exception types to HTTP Status Code, use predefined handlers, or create your own.
8+
You can map specific exception types to HTTP Status Codes, use predefined handlers, or create your own.
99

1010
You can throw an exception from anywhere in your codebase and ExceptionMapper will handle it according to your specifications.
1111
This makes it a breeze to uniformize exception handling in a REST API.
1212

13-
All of the handlers are iterated through, in order, so you can build a pipeline to handle exceptions where multiple handlers have a single responsibility.
13+
All the handlers are iterated through, in order, so you can build a pipeline to handle exceptions where multiple handlers have a single responsibility.
1414
For example, you could have handlers that respond to certain exception types, then one or more fallback handlers that react only if no previous handler handled the exception.
1515

16-
Finally, there is a serializer that convert handled exceptions to JSON, in the format of your choice, making your API linear between endpoints and exception types without much effort. The default serializer converts the errors to [Problem Details for HTTP APIs](https://datatracker.ietf.org/doc/html/rfc7807).
17-
18-
## Versioning
19-
20-
The packages follows _semantic versioning_ and use `Nerdbank.GitVersioning` to automatically version packages based on git commits.
21-
22-
### Pre-released
23-
24-
Prerelease packages are packaged code not yet merged to `master`.
25-
The prerelease CI builds are packaged and hosted at [feedz.io](feedz.io), thanks to their "Open Source" subscription.
16+
Finally, there is a serializer that converts handled exceptions to JSON, in the format of your choice, making your API linear between endpoints and exception types without much effort. The default serializer converts the errors to [Problem Details for HTTP APIs](https://datatracker.ietf.org/doc/html/rfc7807).
2617

2718
## How to install
2819

@@ -36,7 +27,7 @@ _You can take a look at the `samples/WebApiSample` project for a working example
3627

3728
## Getting started
3829

39-
You must register the services, and optionally configure/register handlers, and use the middleware that catches exceptions (and that handles the logic).
30+
You must register the services, optionally configure/register handlers, and use the middleware that catches exceptions (and that handles the logic).
4031

4132
**Program.cs**
4233

@@ -76,7 +67,7 @@ public class Startup
7667

7768
## Extending the existing exception
7869

79-
An easy way to manage your custom exceptions is to inherit from the one that are already mapped.
70+
An easy way to manage your custom exceptions is to inherit from the ones that are already mapped.
8071
For example, you could create and throw the following `DroidNotFoundException` and ExceptionMapper will associate it with a 404 Not Found status code because it inherits from `NotFoundException`:
8172

8273
```csharp
@@ -91,7 +82,7 @@ public class DroidNotFoundException : NotFoundException
9182

9283
## Mapping Exception types to status code
9384

94-
If you do not want or can't inherit the provided exceptions, you can map any Exception types to specific status code, like this:
85+
If you do not want or can't inherit the provided exceptions, you can map any Exception types to a specific status code, like this:
9586

9687
```csharp
9788
builder.AddExceptionMapper(builder =>
@@ -188,7 +179,7 @@ ExceptionMapper implements different common exceptions and their handlers, like
188179

189180
# Fallback handler
190181

191-
ExceptionMapper also comes with a fallback handler that convert unhandled exceptions to `500 InternalServerError`. This is an opt-out feature, configured by the `FallbackExceptionHandlerOptions`.
182+
ExceptionMapper also comes with a fallback handler that converts unhandled exceptions to `500 InternalServerError`. This is an opt-out feature, configured by the `FallbackExceptionHandlerOptions`.
192183

193184
You can also configure the `FallbackExceptionHandlerOptions` like the following or under the `ExceptionMapper:FallbackExceptionHandler` key in your settings:
194185

@@ -234,11 +225,11 @@ You can also customize the options from the `appsettings.json` file:
234225
```
235226

236227
Note that the serializer displays the debug information when in development.
237-
Use the `DisplayDebugInformation` function to display the debug info in other environment, like staging or production.
228+
Use the `DisplayDebugInformation` function to display the debug info in other environments, like staging or production.
238229

239230
## Property names
240231

241-
To change the way the property name are serialized, you can configure the `JsonOptions` and change the `PropertyNamingPolicy` property.
232+
To change the way the property names are serialized, you can configure the `JsonOptions` and change the `PropertyNamingPolicy` property.
242233

243234
**.NET 8+**
244235

@@ -258,7 +249,7 @@ builder.Services.Configure<JsonOptions>(options => {
258249

259250
### Dictionary keys
260251

261-
For .NET 7+ projects, ExceptionMapper sets the `DictionaryKeyPolicy` property to the `PropertyNamingPolicy` property value so dictionaries are serialized the same way as the normal properties.
252+
For .NET 7+ projects, ExceptionMapper sets the `DictionaryKeyPolicy` property to the `PropertyNamingPolicy` property value, so dictionaries are serialized the same way as the normal properties.
262253

263254
## Ensuring a property is not serialized
264255

@@ -289,60 +280,61 @@ services.AddSingleton<IExceptionSerializer, MySerializationHandler>();
289280
builder.AddExceptionMapper();
290281
```
291282

283+
## Versioning
284+
285+
The package follows _semantic versioning_ and uses `Nerdbank.GitVersioning` to automatically version packages based on git commits.
286+
287+
### Pre-released
288+
289+
Prerelease packages are packaged code not yet merged to the `main` branch.
290+
The prerelease CI builds are packaged and hosted at [feedz.io](feedz.io), thanks to their "Open Source" subscription.
291+
292292
# Release notes
293293

294294
## 3.0
295295

296-
The version 3 of ExceptionMapper is a major rewrite that simplifies the codebase and usage of the library. Here are a few important changes:
296+
Version 3 of ExceptionMapper is a major rewrite that simplifies the codebase and usage of the library. Here are a few important changes:
297297

298298
- Add support to .NET 7 and .NET 8.
299299
- Remove transitive dependency on JSON.NET (`Newtonsoft.Json`).
300300
- Drop support for .NET Standard 2.0 because `ExceptionMapper` depends on the `HttpContext` class which requires a `<FrameworkReference Include="Microsoft.AspNetCore.App" />` which is not compatible with `netstandard2.0`.
301-
- Merge all assemblies in `ForEvolve.ExceptionMapper` but `ForEvolve.ExceptionMapper.Scrutor` and removed `ForEvolve.ExceptionMapper.Scrutor` althogether.
301+
- Merge all assemblies in `ForEvolve.ExceptionMapper` but `ForEvolve.ExceptionMapper.Scrutor` and removed `ForEvolve.ExceptionMapper.Scrutor` altogether.
302302
- Replace the `AddMvcCore` call by registering a copy of the `DefaultProblemDetailsFactory` using a `TryAddSingleton` call, so you must register your custom `ProblemDetailsFactory` implementation before `AddExceptionMapper`. The good news is, if you are using a custom factory, the `ProblemDetailsSerializationHandler` will use it!
303303
> Removing the copy of the `DefaultProblemDetailsFactory` class could be resolved by https://github.com/dotnet/aspnetcore/issues/49982
304304
- Calling `AddExceptionMapper()` now registers the common exceptions and the serializer automatically.
305305
- The `Order` property was removed from the `IExceptionHandler` interface. The system uses the registration order instead.
306-
- The interface now leverage a serialzier implementing the `IExceptionSerializer` interface. The serializer no longer implements the `IExceptionHandler` interface.
306+
- The interface now leverages a serializer implementing the `IExceptionSerializer` interface. The serializer no longer implements the `IExceptionHandler` interface.
307307
- By default, `ProblemDetailsSerializationOptions` is bound to the section `ExceptionMapper:ProblemDetailsSerialization` and `FallbackExceptionHandlerOptions` is bound to the section `ExceptionMapper:FallbackExceptionHandler`.
308308

309309
### Breaking changes .NET 7+
310310

311311
- Remove the `ContentType` and `JsonSerializerOptions` properties from the `ProblemDetailsSerializationOptions` class (`ForEvolve.ExceptionMapper.Serialization.Json`).
312-
- The `ProblemDetailsSerializationHandler` class now leverages the `IProblemDetailsService` interface to write the `ProblemDetails` object to the response stream instead of serializing it with the `JsonSerializer`, relinguishing the control of the process to .NET.
312+
- The `ProblemDetailsSerializationHandler` class now leverages the `IProblemDetailsService` interface to write the `ProblemDetails` object to the response stream instead of serializing it with the `JsonSerializer`, relinquishing the control of the process to .NET.
313313
- The `ProblemDetailsSerializationHandler` leverages the `JsonOptions` class to ensure the names are formatted according to the `PropertyNamingPolicy` object. The default is `camelCase`.
314314
- ExceptionMapper sets the `DictionaryKeyPolicy` property to the `PropertyNamingPolicy` property value so dictionaries are serialized the same way as the normal properties.
315315

316-
## 2.0
316+
## 2.0 (deprecated)
317317

318318
- Drop .NET Core 3.1 support
319319
- Add support for .NET 6.0
320320

321-
## 1.1
321+
## 1.1 (deprecated)
322322

323323
- Add a handler that serializes exceptions to `ProblemDetails` (JSON)
324324
- Add the `ForEvolve.ExceptionMapper.Serialization.Json` project
325325

326-
## 1.0
327-
328-
- Initial release (no yet released)
329-
330-
# Future/To do
331-
332-
Here is a list of what I want to do:
326+
## 1.0 (deprecated)
333327

334-
- [ ] Improve overall test coverage.
335-
- [ ] Implement custom type converter. The serializer would either use the converter or fall back to the reflection-based code if no type converter is available.
336-
- [ ] Create a more "real-life" code sample.
328+
- Initial release (not yet released).
337329

338330
# Found a bug or have a feature request?
339331

340332
Please open an issue and be as clear as possible; see _How to contribute?_ for more information.
341333

342334
# How to contribute?
343335

344-
If you would like to contribute to the project, first, thank you for your interest, and please read [Contributing to ForEvolve open source projects](https://github.com/ForEvolve/ForEvolve.DependencyInjection/tree/master/CONTRIBUTING.md) for more information.
336+
If you would like to contribute to the project, first, thank you for your interest, and please read [Contributing to ForEvolve open source projects](https://github.com/ForEvolve/Toc/blob/master/CONTRIBUTING.md) for more information.
345337

346338
## Contributor Covenant Code of Conduct
347339

348-
Also, please read the [Contributor Covenant Code of Conduct](https://github.com/ForEvolve/ForEvolve.DependencyInjection/tree/master/CODE_OF_CONDUCT.md) that applies to all ForEvolve repositories.
340+
Also, please read the [Contributor Covenant Code of Conduct](https://github.com/ForEvolve/Toc/blob/master/CODE_OF_CONDUCT.md) that applies to all ForEvolve repositories.

src/Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<Nullable>enable</Nullable>
1616
<ImplicitUsings>enable</ImplicitUsings>
1717
</PropertyGroup>
18+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
19+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
20+
</PropertyGroup>
1821
<ItemGroup>
1922
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
2023
<PackageReference Include="Nerdbank.GitVersioning">

src/ForEvolve.ExceptionMapper/ForEvolve.ExceptionMapper.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(FETargetFrameworks)</TargetFrameworks>
55
</PropertyGroup>
6-
6+
77
<ItemGroup>
88
<FrameworkReference Include="Microsoft.AspNetCore.App" />
99
<PackageReference Include="ForEvolve.Core" Version="2.3.5" />
1010
</ItemGroup>
11+
<ItemGroup>
12+
<None Include="../../README.md" Pack="true" PackagePath="\"/>
13+
<None Include="../../LICENSE" Pack="true" PackagePath="\"/>
14+
</ItemGroup>
1115
</Project>

src/ForEvolve.ExceptionMapper/Serialization/Json/ProblemDetailsSerializationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task ExecuteAsync(ExceptionHandlingContext ctx)
8080
{
8181
var traceIdKey = "traceId";
8282
problemDetails.Extensions.Remove(traceIdKey);
83-
problemDetails.Extensions.Add(FormatName(traceIdKey), traceId);
83+
problemDetails.Extensions.Add(FormatName(traceIdKey), traceId);
8484
}
8585

8686
// Transfer non-excluded and non-JsonIgnored properties to the problem details.

0 commit comments

Comments
 (0)