def make_error_router():
sink_observer = None<EOL>def on_subscribe(observer):<EOL><INDENT>nonlocal sink_observer<EOL>sink_observer = observer<EOL>def dispose():<EOL><INDENT>nonlocal sink_observer<EOL>sink_observer = None<EOL><DEDENT>return dispose<EOL><DEDENT>def route_error(obs, convert):<EOL><INDENT>"""<STR_LIT>"""<EOL>def catch_error(e):<EOL><INDENT>sink_observer.on_next(convert(e))<EOL>return Observable.empty()<EOL><DEDENT>return obs.catch_exception(catch_error)<EOL><DEDENT>def catch_or_flat_map(source, error_map, source_map=lambda i: i):<EOL><INDENT>return source.flat_map(lambda i: route_error(source_map(i), error_map))<EOL><DEDENT>return Observable.create(on_subscribe), catch_or_flat_map<EOL>
Creates an error router

    An error router takes a higher order observable a input and returns two
    observables: One containing the flattened items of the input observable
    and another one containing the flattened errors of the input observable.

    .. image:: ../docs/asset/error_router.png
        :scale: 60%
        :align: center

    Returns
    -------
    error_observable: observable
        An observable emitting errors remapped.

    route_error: function
        A lettable function routing errors and taking three parameters:
        * source: Observable (higher order). Observable with errors to route.
        * error_map: function. Function used to map errors before routing them.
        * source_map: function. A function used to select the observable from each item is source.

    Examples
    --------

    >>> sink, route_error = make_error_router()
        my_observable.let(route_error, error_map=lambda e: e)