<commit_before>Error Handlers
--------------

Every ``Route`` implements a coroutine ``error_handler`` that can be used as an error hook.
This hook are called when unhandled exceptions happen and by default it will only log the
error and **not** acknowledge the message.

``Route`` accepts a callable parameter, ``error_handler``, so you can pass a custom function or
coroutine to replace the default error handler behavior.

The callable should be similar to::

    async def custom_error_handler(exc_type, exc, message):
        ... custom code here ...
        return True

     # Route(..., error_handler=custom_error_handler)


The return value determines if the message that originated the error will be acknowledged or not.
``True`` means acknowledge it, ``False`` will only ignore the message (default behavior).<commit_msg>Add sentry integration doc<commit_after>Error Handlers
--------------

Every ``Route`` implements a coroutine ``error_handler`` that can be used as an error hook.
This hook are called when unhandled exceptions happen and by default it will only log the
error and **not** acknowledge the message.

``Route`` accepts a callable parameter, ``error_handler``, so you can pass a custom function or
coroutine to replace the default error handler behavior.

The callable should be similar to::

    async def custom_error_handler(exc_type, exc, message):
        ... custom code here ...
        return True

     # Route(..., error_handler=custom_error_handler)


The return value determines if the message that originated the error will be acknowledged or not.
``True`` means acknowledge it, ``False`` will only ignore the message (default behavior).


Sentry
~~~~~~


To integrate with `sentry`_ you will need the `raven`_ client and your account DSN.

Then you can automatically create an ``error_handler`` with the following code::

    from loafer.ext.sentry import sentry_handler
    from raven import Client

    client = Client(dsn=..., **options)
    error_handler = sentry_handler(client, delete_message=True)


The optional ``delete_message`` parameter controls the message acknowledgement
after the error report. By default, ``delete_message`` is ``False``.

The ``error_handler`` defined can be set on any ``Route`` instance.

.. _sentry: https://sentry.io/
.. _raven: https://github.com/getsentry/raven-python
{'fraction_non_alphanumeric': 0.0970625798212005, 'fraction_numerical': 0.0, 'mean_word_length': 4.021367521367521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '945940', 'n_tokens_mistral': 603, 'n_tokens_neox': 592, 'n_words': 285}