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

Commit

Permalink
Merge pull request #23 from AngeloDotNet/7-status-code-management-409
Browse files Browse the repository at this point in the history
7 status code management 409
  • Loading branch information
AngeloDotNet authored Aug 29, 2023
2 parents ffc6521 + 90d7a6d commit 451a710
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ This library is an ad hoc code customization used in my private/work projects th
| 405 | Exception.NotAllowedException | Response.MethodNotAllowed | available |
| 406 | Exception.NotAcceptableException | Response.NotAcceptable | available |
| 408 | Exception.RequestTimeoutException | Response.RequestTimeout | available |
| 409 | Exception.ConflictException | Response.Conflict | coming soon |
| 409 | Exception.ConflictException | Response.Conflict | available |
| 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | coming soon |
| 500 | Exception.InternalServerErrorException | Response.InternalServerError | coming soon |
| 501 | Exception.NotImplementedException | Response.NotImplemented | coming soon |
Expand Down
16 changes: 16 additions & 0 deletions src/CustomLibrary.ProblemDetails/Exception/ConflictException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CustomLibrary.ProblemDetails.Exception;

public class ConflictException : System.Exception
{
public ConflictException()
{
}

public ConflictException(string message) : base(message)
{
}

public ConflictException(string message, System.Exception innerException) : base(message, innerException)
{
}
}
22 changes: 22 additions & 0 deletions src/CustomLibrary.ProblemDetails/Response/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,26 @@ public static ObjectResult RequestTimeout(HttpContext httpContext, System.Except

return result;
}

public static ObjectResult Conflict(HttpContext httpContext, System.Exception exc)
{
var statusCode = StatusCodes.Status409Conflict;
var problemDetails = new CustomProblemDetails
{
Status = statusCode,
Type = $"https://httpstatuses.com/{statusCode}",
Instance = httpContext.Request.Path,
Title = "Conflict"
};

problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier);
problemDetails.Extensions.Add("errors", exc.Message);

var result = new ObjectResult(problemDetails)
{
StatusCode = statusCode
};

return result;
}
}

0 comments on commit 451a710

Please sign in to comment.