c# - Intercept webapi json formatting errors -


I exception occurs when you have a way to send intercept distorted json a WebAPI endpoint want, so that I can return to resist a meaningful error codes as only 500 (for example, "go to your broken JSON fix or hell") are

You can create your custom accreditation filter attribute by getting:

  Public class ValidationFilterAttribute: ActionFilterAttribute {Public Override Zero OnActionExecuting (HttpActionContext actionContext) {if (actionContext.ModelState. Iframe} {actionContext.Response = actionContext .equest .CreateErrorResponse (HttpStatusCode.BadRequest, actionContext.ModelState); }}}  

Now, you are either with it can decorate your actions:

  [HttpGet] [ValidationFilter ()] public string DoSomethingCool ()  

or it through your config :

  config.Filters.Add (new ValidationFilterAttribute ());  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Algorithm negotiation fail SSH in Jenkins -

java - Messages from .properties file do not display UTF-8 characters -