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

Commit 90d7a6d

Browse files
committed
Implementata exception status code 409
1 parent ac47d30 commit 90d7a6d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
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)