c# - 400 Bad Request not going through custom exception handler -


this 400 bad request not go through exception handler:

{   "message": "the request invalid.",   "messagedetail": "the parameters dictionary contains null entry parameter 'subscriptionid' of non-nullable type 'system.guid' method 'system.net.http.httpresponsemessage get(system.guid)' in 'product.controllers.itemcontroller'. optional parameter must reference type, nullable type, or declared optional parameter." } 

on webapiconfig.cs have this:

config.services.replace(typeof(iexceptionhandler), new httpexceptionhandler()); 

every exception thrown action, repository, service layer levels handled exception handler. error , generic webapi exception handler kicks in.

how should fix in order exception go through exception handler?

i have same problem, here solution

1- add filter

public class requestnovalidoattribute : actionfilterattribute {     public override void onactionexecuting(httpactioncontext actioncontext)     {         if (!actioncontext.modelstate.isvalid)         {             var response = new httpresponsemessage(httpstatuscode.badrequest)             {                 requestmessage = actioncontext.request,                 content = new stringcontent("formato no vĂ¡lido.")             };             actioncontext.response = response;         }     } } 

2- add filter in webapiconfig.cs

config.filters.add(new requestnovalidoattribute()); 

Comments