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

Commit 451a710

Browse files
authored
Merge pull request #23 from AngeloDotNet/7-status-code-management-409
7 status code management 409
2 parents ffc6521 + 90d7a6d commit 451a710

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
@@ -52,7 +52,7 @@ This library is an ad hoc code customization used in my private/work projects th
5252
| 405 | Exception.NotAllowedException | Response.MethodNotAllowed | available |
5353
| 406 | Exception.NotAcceptableException | Response.NotAcceptable | available |
5454
| 408 | Exception.RequestTimeoutException | Response.RequestTimeout | available |
55-
| 409 | Exception.ConflictException | Response.Conflict | coming soon |
55+
| 409 | Exception.ConflictException | Response.Conflict | available |
5656
| 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | coming soon |
5757
| 500 | Exception.InternalServerErrorException | Response.InternalServerError | coming soon |
5858
| 501 | Exception.NotImplementedException | Response.NotImplemented | 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 ConflictException : System.Exception
4+
{
5+
public ConflictException()
6+
{
7+
}
8+
9+
public ConflictException(string message) : base(message)
10+
{
11+
}
12+
13+
public ConflictException(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
@@ -177,4 +177,26 @@ public static ObjectResult RequestTimeout(HttpContext httpContext, System.Except
177177

178178
return result;
179179
}
180+
181+
public static ObjectResult Conflict(HttpContext httpContext, System.Exception exc)
182+
{
183+
var statusCode = StatusCodes.Status409Conflict;
184+
var problemDetails = new CustomProblemDetails
185+
{
186+
Status = statusCode,
187+
Type = $"https://httpstatuses.com/{statusCode}",
188+
Instance = httpContext.Request.Path,
189+
Title = "Conflict"
190+
};
191+
192+
problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
193+
problemDetails.Extensions.Add("errors", exc.Message);
194+
195+
var result = new ObjectResult(problemDetails)
196+
{
197+
StatusCode = statusCode
198+
};
199+
200+
return result;
201+
}
180202
}

0 commit comments

Comments
 (0)