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
Post a Comment