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 #21 from AngeloDotNet/8-status-code-management-406
Browse files Browse the repository at this point in the history
8 status code management 406
  • Loading branch information
AngeloDotNet authored Aug 23, 2023
2 parents 592d200 + c71e882 commit 382ae31
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 @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
22 changes: 22 additions & 0 deletions src/CustomLibrary.ProblemDetails/Response/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 382ae31

Please sign in to comment.