question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Error Api Response Model

See original GitHub issue

I have a similar use case to https://github.com/JeremySkinner/FluentValidation/issues/548

Except for my use case I want to have a global filter that translates the validation error into a custom model like.

[
   {
      "errorCode" : 82
      "message": "foo was bar"
   }
]

I do not need the ValidationResult in my controller action. Is this possible?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Lutandocommented, Jul 4, 2018

Apologies, my controller had a filter on it [ApiController] attribute on it which took precedence over the global filter. Everything is good 😃 thanks for your help

0reactions
JeremySkinnercommented, Jul 4, 2018

The automatic integration being .AddFluentValidation()?

Yes, so long as you also register the validators with the container as per https://fluentvalidation.net/aspnet.html#asp-net-core

For some reason my global ActionFilterAttributes are not executing when added as global MvcFilters when I use full integration with the AspNetCore integration

Not sure I understand. FluentValidation doesn’t do anything with filters so wouldn’t be impacting this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Error Message Handling for REST API
In this tutorial, we'll discuss how to implement a global error handler for a Spring REST API. We will use the semantics of...
Read more >
Best Practices for REST API Error Handling
Custom Error Message Handling for REST API ... Based on the response code, a client can surmise the result of a particular request....
Read more >
Custom error response in Web Api
I would like to create a custom error message to pass errors as json. Something like: if (!ModelState.IsValid) return ModelHasErrors(errors);.
Read more >
Custom Error Responses With ASP.NET Core 6 Web API ...
Custom Error Responses With ASP.NET Core 6 Web API and FluentValidation · Create a Web API Project · Implement Endpoints · Validate Requests...
Read more >
Create a custom error response via API
Configure custom error responses as rules belonging to the http_custom_errors phase. Use the Rulesets API to create custom error responses ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found