0

I am having issues with ASP.NET Core having custom validation responses different than our custom response object. We have a certain format needed and many of the automatic responses provided are a different format than our own.

For example Validation responses, Ok/BadRequest/NotFound/NoContent, and unsupported media type.

I am curious how to go about this without creating a custom ControllerBase class that overrides all these but am still looking for how to deal with the automatic responses as well.

I still want to keep the automatic responses I just want them to be of my own custom type.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
mjwrazor
  • 1,866
  • 2
  • 26
  • 42
  • What do you mean by not creating a custom ControllerBase class that overrides all of this? Do you want to return the error encountered in json format? Is it mentioned in this article?https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-6.0 – Tupac Jan 10 '22 at 06:57
  • @Chaodeng I ended up extending `ActionFilterAttribute` and adding that to my own custom controller and editing the responses for responses like `Ok()` and then adding a custom Error controller for 404 and 401 automatic responses as seen in this post https://stackoverflow.com/questions/31606521/displaying-a-404-not-found-page-for-asp-net-core-mvc, but no that article did not help. – mjwrazor Jan 10 '22 at 16:04

0 Answers0