diff --git a/README.md b/README.md index 7e2ec26..f0b026f 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ This library is an ad hoc code customization used in my private/work projects th | 403 | Exception.ForbiddenException | Response.Forbidden | available | | 404 | Exception.NotFoundException | Response.NotFound | available | | 405 | Exception.NotAllowedException | Response.MethodNotAllowed | available | -| 406 | Exception.NotAcceptableException | Response.NotAcceptable | coming soon | +| 406 | Exception.NotAcceptableException | Response.NotAcceptable | available | | 408 | Exception.RequestTimeoutException | Response.RequestTimeout | coming soon | | 409 | Exception.ConflictException | Response.Conflict | coming soon | | 422 | Exception.UnprocessableEntityException | Response.UnprocessableEntity | coming soon | diff --git a/src/CustomLibrary.ProblemDetails/Exception/NotAcceptableException.cs b/src/CustomLibrary.ProblemDetails/Exception/NotAcceptableException.cs new file mode 100644 index 0000000..6206489 --- /dev/null +++ b/src/CustomLibrary.ProblemDetails/Exception/NotAcceptableException.cs @@ -0,0 +1,16 @@ +namespace CustomLibrary.ProblemDetails.Exception; + +public class NotAcceptableException : System.Exception +{ + public NotAcceptableException() + { + } + + public NotAcceptableException(string message) : base(message) + { + } + + public NotAcceptableException(string message, System.Exception innerException) : base(message, innerException) + { + } +} \ No newline at end of file diff --git a/src/CustomLibrary.ProblemDetails/Response/Response.cs b/src/CustomLibrary.ProblemDetails/Response/Response.cs index 9c0859d..90e3cd0 100644 --- a/src/CustomLibrary.ProblemDetails/Response/Response.cs +++ b/src/CustomLibrary.ProblemDetails/Response/Response.cs @@ -133,4 +133,26 @@ public static ObjectResult MethodNotAllowed(HttpContext httpContext, System.Exce return result; } + + public static ObjectResult NotAcceptable(HttpContext httpContext, System.Exception exc) + { + var statusCode = StatusCodes.Status406NotAcceptable; + var problemDetails = new CustomProblemDetails + { + Status = statusCode, + Type = $"https://httpstatuses.com/{statusCode}", + Instance = httpContext.Request.Path, + Title = "NotAcceptable" + }; + + problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? httpContext.TraceIdentifier); + problemDetails.Extensions.Add("errors", exc.Message); + + var result = new ObjectResult(problemDetails) + { + StatusCode = statusCode + }; + + return result; + } } \ No newline at end of file