Add hook for customizing exceptions

The exceptions can be customized via a new ErrorHandler class, which is
responsible for returning customized exceptions during synchronous
requests.