开发者

Business Layer errors and Service Layer handling - Best way?

开发者 https://www.devze.com 2023-02-15 12:43 出处:网络
We\'re building a large web app that has numerous layers.In order to communicate to the business layer we\'re using a service layer that the web layer calls when data is needed.Unfortunately, it seems

We're building a large web app that has numerous layers. In order to communicate to the business layer we're using a service layer that the web layer calls when data is needed. Unfortunately, it seems that if exceptions are thrown in the business layer, it seems that the services on the web side are wrapping the 开发者_如何学Pythonexceptions and re-throwing them. We're looking for a clear way to encapsulate the error and log it, without WCF wrapping a new exception around the original.

Thanks


FWIW, each of our exposed WCF Service Layer methods catches a System.Exception and passes it off to a HandleException helper (this could also be a base service class method I guess)

HandleException:

  1. Logs the error
  2. Applies the exception reformatting to SOAP faults (currently we are using WCF Exception Shielding)
  3. Applies any exception-specific handling (of the format if (ex is SomeTypeOfException) ...)


There are various ways to do this. The solution you presented isn't half bad I believe, though it doesn't scale much (mixing business specific error handling with web-related code creates some sort of coupling). All this depends on your achitecture: you could add a superficial, lightweight layer that translates business errors into web errors, that are handled in the web layer error handling code. You could also you AoP and intercept the calls and translate the errors for the layers above.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号