✅ Using services.PostConfigure<ApiBehaviorOptions> to log Model Validation errors in dotnet6?
Is this a safe implementation to log Model Validation errors in dotnet6?
15 Replies
the try/catches are sus
at least, the outer one is
Why're you trying to log an error, just to log it on catch?
and you shouldn't be serializing logs to JSON
...?
that's a result of trying to do formatting where it doesn't belong
Just remove the formatting.
formatting is the logger sink's resposibility
And that try catch block.
Wouldn't it be better to log the information with a model?
....yes, exactly
And then let the UI format it.
For example, create a class with Error, Message, Stack trace, etc.
Or however you want to create this model.
in other words.... each sink serializes and formats how it wants to, yes
Yes.
got it...thanks guys. yeah, I was mostly generally worried about my use of throwing returning unexpected model validation errors, when
builtInFactory
, descriptor
,actionName
,controllerName
and services.PostConfigure<ApiBehaviorOptions>
in general.
A teammate rewrote an API to .net 6 minial apis with the <nullable>
option on, and it made all the Models with things like string
start null
was passed, because of a rush to refactor.
This is an attempt to capture these instance and to try and communicate to consumers to fix or for us to re-evaluate our model props and turn things like string
back to string?
lack of confidence in the implementation, really ^^' and unfamiliarity with options.InvalidModelStateResponseFactory
in general.Ahh.
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.