Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
Updated documentation and nuget yml. Updated cancellation tokens to d…
Browse files Browse the repository at this point in the history
…efault instead of new (missed some from PR #4) (#7)
  • Loading branch information
1eyewonder authored Feb 21, 2022
1 parent 56e059c commit 82f1bfd
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 38 deletions.
30 changes: 21 additions & 9 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

jobs:
deploy:
publish:
name: 'build, pack & publish'
runs-on: ubuntu-latest
steps:
Expand All @@ -16,13 +16,25 @@ jobs:
- name: 'Install dotnet'
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
dotnet-version: 6.0.x

- name: 'Restore packages'
run: dotnet restore ${{ env.PROJECT_PATH }}

- name: 'Build project'
run: dotnet build ${{ env.PROJECT_PATH }} --no-restore --configuration Release
- name: 'Publish Abstractions'
id : publish_abstractions_nuget
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: src/ExceptionAll.Abstractions/ExceptionAll.Abstractions.csproj
NUGET_KEY: ${{ secrets.NUGET_AUTH_TOKEN }}

- name: 'Publish ExceptionAll'
id: publish_exceptionall_nuget
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: src/ExceptionAll/ExceptionAll.csproj
NUGET_KEY: ${{ secrets.NUGET_AUTH_TOKEN }}

- name: 'Push package'
run: dotnet nuget push ${{ env.PACKAGE_OUTPUT_DIRECTORY }}\*.nupkg -k ${{ secrets.NUGET_AUTH_TOKEN }} -s ${{ env.NUGET_SOURCE_URL }}
- name: 'Publish Client'
id: publish_client_nuget
uses: rohith/publish-nuget@v2
with:
PROJECT_FILE_PATH: src/ExceptionAll.Client/ExceptionAll.Client.csproj
NUGET_KEY: ${{ secrets.NUGET_AUTH_TOKEN }}
57 changes: 37 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ExceptionAll

Package | Version | Downloads
-----|------|-------
<b>ExceptionAll</b> | [![Nuget version](https://img.shields.io/nuget/v/ExceptionAll)](https://www.nuget.org/packages/ExceptionAll/) | [![Nuget downloads](https://img.shields.io/nuget/dt/ExceptionAll)](https://www.nuget.org/packages/ExceptionAll/)
<b>ExceptionAll.Abstractions</b> | [![Nuget version](https://img.shields.io/nuget/v/ExceptionAll.Abstractions)](https://www.nuget.org/packages/ExceptionAll.Abstractions/) | [![Nuget downloads](https://img.shields.io/nuget/dt/ExceptionAll.Abstractions)](https://www.nuget.org/packages/ExceptionAll.Abstractions/)
<b>ExceptionAll.Client</b> | [![Nuget version](https://img.shields.io/nuget/v/ExceptionAll.Client)](https://www.nuget.org/packages/ExceptionAll.Client/) | [![Nuget downloads](https://img.shields.io/nuget/dt/ExceptionAll.Client)](https://www.nuget.org/packages/ExceptionAll.Client/)
| Package | Version | Downloads |
|----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| <b>ExceptionAll</b> | [![Nuget version](https://img.shields.io/nuget/v/ExceptionAll)](https://www.nuget.org/packages/ExceptionAll/) | [![Nuget downloads](https://img.shields.io/nuget/dt/ExceptionAll)](https://www.nuget.org/packages/ExceptionAll/) |
| <b>ExceptionAll.Abstractions</b> | [![Nuget version](https://img.shields.io/nuget/v/ExceptionAll.Abstractions)](https://www.nuget.org/packages/ExceptionAll.Abstractions/) | [![Nuget downloads](https://img.shields.io/nuget/dt/ExceptionAll.Abstractions)](https://www.nuget.org/packages/ExceptionAll.Abstractions/) |
| <b>ExceptionAll.Client</b> | [![Nuget version](https://img.shields.io/nuget/v/ExceptionAll.Client)](https://www.nuget.org/packages/ExceptionAll.Client/) | [![Nuget downloads](https://img.shields.io/nuget/dt/ExceptionAll.Client)](https://www.nuget.org/packages/ExceptionAll.Client/) |


## Table of Contents
Expand All @@ -13,12 +13,15 @@ Package | Version | Downloads
- [Server Side](#server-side)
- [Client Side](#client-side)
- [Example Code](#example-code)
- [Server](#server)
- [Client](#client)
- [Swagger Examples](#swagger-examples)
- [Extending ExceptionAll](#extending-exceptionall)


________
## Summary
ExceptionAll is a library for adding global error handling to Web API solutions using .NET Core. Its goals are to:
ExceptionAll is a library for adding global error handling to Web API solutions as well as streamline http client interactions. Its goals are to:
1. Reduce code noise by reducing the need for 'try-catch' blocks in code
2. Provide a single source of responsibility for configuring and maintaining API error handling logic
3. Allow for the customization of error response data and logging actions
Expand All @@ -28,7 +31,7 @@ ExceptionAll is a library for adding global error handling to Web API solutions
_______
## Setup

<i>Note: ExceptionAll offers both front and backend solutions but they do not need to be mutally exclusive. Please read over what each solution does and how it is applicable to your problem/application</i>
<i>Note: ExceptionAll offers both front and backend solutions but they do not need to be mutually exclusive. Please read over what each solution does and how it is applicable to your problem/application</i>

### Server Side
1. Install ExceptionAll & ExceptionAll.Abstractions nuget packages
Expand All @@ -38,6 +41,7 @@ _______
2. ContextConfiguration
- Allows the developer to extend the standard response object by adding details from the HttpContext. Options become limitless since custom headers are accessible.
- As the context properties are updated, the Swagger documentation should also be updated as well.
- The 'Errors' key is reserved by ExceptionAll

```csharp
public class ExceptionAllConfiguration : IExceptionAllConfiguration
Expand Down Expand Up @@ -78,14 +82,17 @@ _______
1. Install both ExceptionAll.Client & ExceptionAll.Abstractions nuget packages
2. Add the following code within your Program.cs file in order to inject the applicable services


```csharp
```csharp
using ExceptionAll.Client.Helpers;

builder.Services.AddExceptionAllClientServices();
builder.Services.AddHttpClient();
```
a. In client use, you will use 'IExceptionAllClientFactory' which is a wrapper around the standard .NET IHttpClientFactory interface. If clients are needed to be configured differently for different endpoints, simply add additional HttpClients with the applicable configurations.
_______
## Example Code

### Server
1. The default API response provided by ExceptionAll. This simulates an uncaught exception in your API code. This response will also be returned for specific exception types not initially considered during configuration.
1. API Controller code

Expand All @@ -107,7 +114,7 @@ _______
```
2. API Response

![alt text](ReadMeImages\v4\ApiControllerStandardResponse.PNG)
![alt text](ReadMeImages/v4/ApiControllerStandardResponse.PNG)

2. This example shows catching an exception configured in the configuration class. (See above configuration code)
1. API Controller code
Expand All @@ -124,7 +131,7 @@ _______
```
1. API Response. The properties match what we see in our configuration, seen further up on the page.

![alt text](ReadMeImages\v4\ArgumentNullRefResponse.PNG)
![alt text](ReadMeImages/v4/ArgumentNullRefResponse.PNG)

3. There may be times where an ExceptionAll response is undesired. To get a non-ExceptionAll response, just wrap the controller/endpoint code with a standard 'try-catch' block and return the new, desired object.
1. API Controller code
Expand All @@ -147,7 +154,7 @@ _______
```
1. API Response

![alt text](ReadMeImages\v4\NonExceptionAllResponse.PNG)
![alt text](ReadMeImages/v4/NonExceptionAllResponse.PNG)

4. This example covers manual response generation, for times developers want to return caught exceptions with a special message and/or a surface list of errors to the user
1. API Controller code
Expand Down Expand Up @@ -181,8 +188,22 @@ _______
```
1. API Response

![alt text](ReadMeImages\v4\ManuallyReturnedResponse.PNG)
![alt text](ReadMeImages/v4/ManuallyReturnedResponse.PNG)

### Client
1. Make sure to inject the ExceptionAllClient factory wherever you are trying to make HttpClient calls
```csharp
@inject IExceptionAllClientFactory _exceptionAllClientFactory
```
2. Create a HttpClient like you normally would. Two examples below
```csharp
// Standard client creation
IExceptionAllClient ExceptionAllClient = _exceptionAllClientFactory.CreateClient();

// Creating named HttpClient configured in IOC
IExceptionAllClient ClientWithHeader = _exceptionAllClientFactory.CreateClient("Test");
```
3. Execute one of the interface methods in order to call a http CRUD operation
_______

## Swagger Examples
Expand Down Expand Up @@ -228,7 +249,7 @@ In order to provide the Swagger examples, add attributes with the return object

The above code should give you the following Swagger response examples:

![alt text](ReadMeImages\v4\SwaggerExamples.PNG)
![alt text](ReadMeImages/v4/SwaggerExamples.PNG)

_______

Expand All @@ -238,13 +259,9 @@ and create additional detail types, follow the below example as a template and i

```csharp

public class BadGatewayDetails : IExceptionAllDetails
public class BadGatewayDetails : BaseDetails
{
public string Title => GetDetails().Title;
public int StatusCode => GetDetails().StatusCode;
public string Message { get; init; } = string.Empty;
public IReadOnlyDictionary<string, object>? ContextDetails { get; init; }
public (int StatusCode, string Title) GetDetails()
public override (int StatusCode, string Title) GetDetails()
{
return (502, "Bad Gateway");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/1eyewonder/ExceptionAll</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageTags>Global Exception Handling</PackageTags>
<PackageTags>global-exception-handling api clean-code netcore csharp swagger</PackageTags>
<Description>Object abstractions for ExceptionAll to be shared in both server and client applications</Description>
<Copyright>2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Bronson Bata</Authors>
<Version>1.0.0</Version>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<PackageVersion>6.0.0</PackageVersion>
</PropertyGroup>

</Project>
4 changes: 2 additions & 2 deletions src/ExceptionAll.Client/Clients/ExceptionAllClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ExceptionAllClient(
/// <exception cref="TaskCanceledException"/>
/// <exception cref="InvalidOperationException"/>
public async ValueTask<T?> PostContentAsync<T>(
string relativeUrl, T content, CancellationToken token = new())
string relativeUrl, T content, CancellationToken token = default)
{
var response = await _httpClient.PostAsJsonAsync(relativeUrl, content, _options, token);
await _validation.ValidateAsync(response);
Expand All @@ -60,7 +60,7 @@ public ExceptionAllClient(
/// <exception cref="TaskCanceledException"/>
/// <exception cref="InvalidOperationException"/>
public async ValueTask<T?> PutContentAsync<T>(
string relativeUrl, T content, CancellationToken token = new())
string relativeUrl, T content, CancellationToken token = default)
{
var response = await _httpClient.PutAsJsonAsync(relativeUrl, content, _options, token);
await _validation.ValidateAsync(response);
Expand Down
5 changes: 3 additions & 2 deletions src/ExceptionAll.Client/ExceptionAll.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/1eyewonder/ExceptionAll</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageTags>Global Exception Handling</PackageTags>
<Description>ExceptionAll client package for better API error handling and serialization</Description>
<PackageTags>global-exception-handling api clean-code netcore csharp</PackageTags>
<Description>ExceptionAll client package for cleaner API error handling and serialization</Description>
<Copyright>2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Bronson Bata</Authors>
<Version>1.0.0</Version>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<PackageVersion>6.0.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ExceptionAll.Client/Interfaces/IExceptionAllClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IExceptionAllClient
/// <param name="content"></param>
/// <param name="token"></param>
/// <returns></returns>
ValueTask<T?> PostContentAsync<T>(string relativeUrl, T content, CancellationToken token = new());
ValueTask<T?> PostContentAsync<T>(string relativeUrl, T content, CancellationToken token = default);

/// <summary>
/// Executes Http Put and returns the requested object type
Expand All @@ -41,5 +41,5 @@ public interface IExceptionAllClient
/// <param name="content"></param>
/// <param name="token"></param>
/// <returns></returns>
ValueTask<T?> PutContentAsync<T>(string relativeUrl, T content, CancellationToken token = new());
ValueTask<T?> PutContentAsync<T>(string relativeUrl, T content, CancellationToken token = default);
}
5 changes: 3 additions & 2 deletions src/ExceptionAll/ExceptionAll.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/1eyewonder/ExceptionAll</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageTags>Global Exception Handling</PackageTags>
<Description>Library for adding global error handling to .NET Core Web API solutions.</Description>
<PackageTags>global-exception-handling api clean-code netcore csharp swagger</PackageTags>
<Description>Adds configurable global error handling to .NET Core Web API solutions</Description>
<Copyright>2022</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Bronson Bata</Authors>
Expand All @@ -17,6 +17,7 @@
<Nullable>enable</Nullable>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<DocumentationFile>/ExceptionAll-swagger.xml</DocumentationFile>
<PackageVersion>6.0.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 82f1bfd

Please sign in to comment.