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

7 status code management 409 #23

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}