I have a lot of legacy code, which is now the backend for the WCF REST service - previously this was the regular WCF service backend, if that matters. I want to implement a mechanism that would catch any exception in any method and analyze it. If this proves to be a known bug, it will be processed and turned into a friendly visual bug.
I know that instead of βregularβ exceptions, I can use FaultException
or WebProtocolException
, but there are many places where exceptions are excluded from the code, and finding all of them is a rather painful option.
I tried to add an endpoint behavior extension that creates a new behavior that overrides the standard WebHttpBehavior.AddServerErrorHandlers
method and adds my error handlers ( IErrorHandler
implementations) to the endpoint manager error handler collector. Inside the error handlers, I analyze the exception and create (or not create) the desired error based on this exception.
I expected this mechanism to return user data for any known exception, but I made a mistake. The good old Microsoft has implemented the wonderful inevitable WebHttpBehavior2
, which unconditionally adds an internal Microsoft.ServiceModel.Web.WebErrorHandler
to the end of the collection of endpoint manager error handlers. This handler ignores all previously handled handlers and recognizes only a small set of exceptions, while most are interpreted as "Internal Server Error" and nothing more.
The question is whether I am on the right track, and is there a way to disable this handler in the WCF REST mechanism or introduce it with a new Exception (for example, when an exception is caught, it is first handled by my handlers and if they throw / return, for example, FaultException, then this new exception is provided instead of Microsoft.ServiceModel.Web.WebErrorHandler
instead of the original). If all my experiments with IErrorHandler
and behavior extensions are useless, what is the alternative? Again, I really do not want to change the logic of throwing exceptions, I want the exceptions to be detected in one place and processed.
Thank you so much!
Michael sagalovich
source share