.net - Better pattern to pass third party exceptions to WCF service callers? -
i developing wcf solution consumes third party services. user inputs , actions validated third party services, meaning service knows has gone wrong when receives third party exceptions.
i need set translate , pass such exceptions callers of own service, because original exceptions' messages technical callers though want them know has gone wrong.
the solution thinking of, use microsoft enterprise library exception handling, custom handlers, catch third party exceptions, , replace original messages more friendly messages (from mapping table or alike) assign error code, throw soap faults. full list of third party exceptions unknown, know of them - unknown ones planning replace generic message , error code, , log original exception.
i think solution work, there may better ways, posting question seek expertise. please share thoughts. main goals have third party exceptions handled elegantly (easy maintain handling code) , messages translated (easily configurable translation settings).
at end, got following solution.
(1) in service access layer (from make calls third party services) of own service, whenever exception or error received third parties, passed on shared dll, error-rewrite library.
(2) library looks if such exception or error has mapping configured (it attempts match error code, message, message regex, etc), xml-based configurations. below example configuration instructs library translate message "your request item itemabcd invalid, because has been assigned user: user1234" "item itemabcd cannot assigned you" own error code item1. library takes new error code , message form new fault can further processed business logic layer.
<!-- each block mapping source error --> <errormapping> <sourceerrorcode></sourceerrorcode> <sourceerrormessage>your request item (\w{0,10}) invalid, because has been assigned user: (\w{0,10}).</sourceerrormessage> <newerrorcode>item1</newerrorcode> <newerrormessage>item {0} cannot assigned you.</newerrormessage> </errormapping>
(3) if third parties have developed new exceptions or erros have not been mapped yet, default fault used, , optionally source error can passed onto user when there no matching mapping.
(4) error logging configured in main project's enterprise library logging block, if configured, source errors, formed new errors, , mapping rules used, etc, logged.
this not perfection solution, worked needs, providing here in case looking potential solutions similar needs.
Comments
Post a Comment