Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit 382ae31

Browse files
authored
Merge pull request #21 from AngeloDotNet/8-status-code-management-406
8 status code management 406
2 parents 592d200 + c71e882 commit 382ae31

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This library is an ad hoc code customization used in my private/work projects th
5050
| 403 | Exception.ForbiddenException | Response.Forbidden | available |
5151
| 404 | Exception.NotFoundException | Response.NotFound | available |
5252
| 405 | Exception.NotAllowedException | Response.MethodNotAllowed | available |
53-
| 406 | Exception.NotAcceptableException | Response.NotAcceptable | coming soon |
53+
| 406 | Exception.NotAcceptableException | Response.NotAcceptable | available |
5454
| 408 | Exception.RequestTimeoutException | Response.RequestTimeout | coming soon |
5555
| 409 | Exception.ConflictException | Response.Conflict | coming soon |
5656
| 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | coming soon |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace CustomLibrary.ProblemDetails.Exception;
2+
3+
public class NotAcceptableException : System.Exception
4+
{
5+
public NotAcceptableException()
6+
{
7+
}
8+
9+
public NotAcceptableException(string message) : base(message)
10+
{
11+
}
12+
13+
public NotAcceptableException(string message, System.Exception innerException) : base(message, innerException)
14+
{
15+
}
16+
}

src/CustomLibrary.ProblemDetails/Response/Response.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,26 @@ public static ObjectResult MethodNotAllowed(HttpContext httpContext, System.Exce
133133

134134
return result;
135135
}
136+
137+
public static ObjectResult NotAcceptable(HttpContext httpContext, System.Exception exc)
138+
{
139+
var statusCode = StatusCodes.Status406NotAcceptable;
140+
var problemDetails = new CustomProblemDetails
141+
{
142+
Status = statusCode,
143+
Type = $"https://httpstatuses.com/{statusCode}",
144+
Instance = httpContext.Request.Path,
145+
Title = "NotAcceptable"
146+
};
147+
148+
problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
149+
problemDetails.Extensions.Add("errors", exc.Message);
150+
151+
var result = new ObjectResult(problemDetails)
152+
{
153+
StatusCode = statusCode
154+
};
155+
156+
return result;
157+
}
136158
}

0 commit comments

Comments
 (0)