asp.net - IExceptionHandler does not handle UnsupportedMediaTypeException -


i have implemented exception handler (iexceptionhandler). handleasync method called when exceptions thrown inside controllers. however, when wrong content-type passed request , unsupportedmediatypeexception thrown in formatter, handler not called. instead default error message returned

{ "message": "the request entity's media type... "exceptionmessage": "no mediatypeformatter ... ... }

i handle exceptions. missing here?

you need catch global exceptionfilterattribute, , filter httpresponseexception, not unsupportedmediatypeexception.

e.g.

httpconfiguration.filters.add(new myhttpresponseexceptionfilterattribute()); 

it turns out unsupportedmediatypeexception wrapped in httpresponseexception time hits webapi pipeline.

httpresponseexception not intercepted iexceptionhandler, because designed transport httpresponsmessage out client. unsupportedmediatypeexception automatically wrapped httpresponsmessage framework, , thrown in httpresponseexception. message see in http response says "unsupportedmediatypeexception", content of httpresponsmessage (httpresponseexception.response.content).


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -