Added method to flatten exceptions before passing them on to the OnError pipeline hook. Issue #1232.