-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom error objects (#25)
Add tests Update readme Bump version
- Loading branch information
Showing
10 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/aspnetcore-exceptionhandler/ExceptionHandling/CustomApiErrorResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace Frogvall.AspNetCore.ExceptionHandling.ExceptionHandling | ||
{ | ||
internal sealed record CustomApiErrorResolver | ||
{ | ||
private readonly Func<ApiError, HttpStatusCode, object> _customApiErrorFunction; | ||
|
||
internal CustomApiErrorResolver(Func<ApiError, HttpStatusCode, object> customApiErrorFunction) | ||
{ | ||
_customApiErrorFunction = customApiErrorFunction; | ||
} | ||
|
||
internal object Resolve(ApiError error, HttpStatusCode statusCode) | ||
{ | ||
return _customApiErrorFunction(error, statusCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/aspnetcore-exceptionhandler/aspnetcore-exceptionhandler.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/aspnetcore-exceptionhandler-test/TestResources/TestCustomErrorObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Net; | ||
using Frogvall.AspNetCore.ExceptionHandling.ExceptionHandling; | ||
|
||
namespace Frogvall.AspNetCore.ExceptionHandling.Test.TestResources | ||
{ | ||
public sealed record TestCustomErrorObject | ||
{ | ||
public TestCustomErrorObject(){} | ||
|
||
public TestCustomErrorObject(ApiError error, HttpStatusCode statusCode) | ||
{ | ||
Detail = error.DetailedMessage; | ||
Status = $"{(int)statusCode}"; | ||
Title = error.Message; | ||
TraceId = error.CorrelationId; | ||
Type = error.Error; | ||
} | ||
|
||
public string Detail { get; set; } | ||
|
||
public string Status { get; set; } | ||
|
||
public string Title { get; set; } | ||
|
||
public string TraceId { get; set; } | ||
|
||
public string Type { get; set; } | ||
} | ||
} |