Debian Codegraph @

docs/config_exceptions.rst

raw
1 Retries
2 --------
3
4 Only for SQL based storage, upon an exception, Flask-Session will retry with backoff up to 3 times. If the operation still fails after 3 retries, the exception will be raised.
5
6 For other storage types, the retry logic is either included or can be configured in the client setup. Refer to the relevant client documentation for more information.
7
8 Redis example with retries on certain errors:
9
10 .. code-block:: python
11
12 from redis.backoff import ExponentialBackoff
13 from redis.retry import Retry
14 from redis.client import Redis
15 from redis.exceptions import (
16 BusyLoadingError,
17 ConnectionError,
18 TimeoutError
19 )
20 ...
21
22 retry = Retry(ExponentialBackoff(), 3)
23 SESSION_REDIS = Redis(host='localhost', port=6379, retry=retry, retry_on_error=[BusyLoadingError, ConnectionError, TimeoutError])
24
25
26 Logging
27 -------------------
28
29 If you want to show user more helpful error messages, you can use `Flask's error handling`_. For example:
30
31 .. code-block:: python
32
33 @app.errorhandler(RedisError)
34 def handle_redis_error(error):
35 app.logger.error(f"Redis error encountered: {error}")
36 return "A problem occurred with our Redis service. Please try again later.", 500
37
38
39 .. _Flask's error handling: https://flask.palletsprojects.com/en/3.0.x/errorhandling/