❔ removing sensitive info (invalid post body)
I currently have the problem that when I make a post request with a body in which an attribute is of incorrect type (DateTime fileld with string). I get an error with too much detail. I want to make it more user readable.
10 Replies
code snippet:
above is the error I get
that looks like a pretty standard error response
It has references to which line of code it originated
I don't think a client should know that
I would like something of the form:
error message: xxx
status code: xxx
i assume that's only included in debug builds of your program
because that debugging data isn't generated in release builds by default
that is possible 🤔
But is it possible to catch or "Filter" this exception?
looks like this is what you'd want https://learn.microsoft.com/en-us/aspnet/core/web-api/handle-errors?view=aspnetcore-7.0#validation-failure-error-response
Handle errors in ASP.NET Core web APIs
Learn about error handling with ASP.NET Core web APIs.
I found out that [ApiController] is responsible for throwing default 400's if there's something wrong with the body of the request
I will read on it, thank you
I thought the section"Use exceptions to modify the response" Would fix it but after implementing it I still wasn't able to catch the repsonse
i linked you directly to the section for changing how validation errors are responded to
oh, thought you wanted me to read the whole article. I will look into that specific part
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.