Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customise the ProblemDetails object when capturing FluentValidation exceptions? #195

Open
iaingymware opened this issue May 25, 2023 · 5 comments

Comments

@iaingymware
Copy link

Hi

I have this up and running when using the default ProblemDetails implementation, however I want to update some of the values, for example the type, to link out to my own documentation specifying the validation requirements.

I can't figure out how to override the ProblemDetails template.

I am currently using the example ProblemDetailsOptionsExtensions class from the samp and I can see it grabs the errors and adds them to a dictionary then passes this into a ProblemDetailsFactory class to generate the response.

How can I override the ProblemDetailsFactory implementation to provide my own Type data?

Thanks

@khellang
Copy link
Owner

Hello @iaingymware! 👋

Have you looked at the sample in this repo? It shows a bunch of ways you can return custom problem details responses. You can return it directly from controllers, use Map functions when configuring the middle ware etc.

It's hard to give more specific feedback without knowing more details about what you want to achieve.

@iaingymware
Copy link
Author

Hi @khellang

I am using your example here linked just below to capture the FluentValidation Validation Exception.

https://github.com/khellang/Middleware/blob/master/samples/ProblemDetails.Sample/ProblemDetailsOptionsExtensions.cs

This uses the ProblemsDetailFactory to generate a ProblemsDetails instance with errors. This works brilliantly however I want to customise the returned ProblemDetails instance.

Is there a way to use the sample Extension class however provide specific values, i.e Type, Title, Detail etc or do I need to write my own factory implementation similar to yours?

Thanks

@khellang
Copy link
Owner

If I'm not mistaken, the factory methods let you specify every single property of the problem details spec.

@iaingymware
Copy link
Author

So I could use this, but it doesnt accept errors as a param:

image

Then we have this, but it accepts ModelStateDictionary (which i dont have as this is a web api) and no errors details:

image

This which accepts error and status code, but no other params:

image

and then this which is the same but an IDictionary version rather than SerializableError:

image

Sorry if I've missed something or I am mistaken, but I dont see a way to pass all custom ProblemDetails values, as well as the errors dictionary?

Thanks

@iaingymware
Copy link
Author

Hi @khellang

Any update on how I should progress with this?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants