Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.
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 @@ -53,7 +53,7 @@ This library is an ad hoc code customization used in my private/work projects th
| 406 | Exception.NotAcceptableException | Response.NotAcceptable | available |
| 408 | Exception.RequestTimeoutException | Response.RequestTimeout | available |
| 409 | Exception.ConflictException | Response.Conflict | available |
| 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | coming soon |
| 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | available |
| 500 | Exception.InternalServerErrorException | Response.InternalServerError | coming soon |
| 501 | Exception.NotImplementedException | Response.NotImplemented | coming soon |
| 502 | Exception.BadGatewayException | Response.BadGateway | coming soon |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace CustomLibrary.ProblemDetails.Exception;

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

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

public UnprocessableEntityException(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 @@ -199,4 +199,26 @@ public static ObjectResult Conflict(HttpContext httpContext, System.Exception ex

return result;
}

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

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

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

return result;
}
}