fusion44 / blitz_api

A management backend for the RaspiBlitz project written in Python / FastAPI
MIT License
19 stars 18 forks source link

Refactor old code to properly raise Exceptions instead of returning error dictionaries #197

Open fusion44 opened 1 year ago

fusion44 commented 1 year ago

See: https://github.com/fusion44/blitz_api/blob/72862f8d6a25d0951097e6e3db79e4d0c10cca3f/app/bitcoind/utils.py#L69

Example:

    except aiohttp.client_exceptions.ClientConnectionError as e:
        return {
            "error": f"Aiohttp client connection error: {str(e)}",
            "status": status.HTTP_503_SERVICE_UNAVAILABLE,
        }

utils.py - redis_get(): https://github.com/fusion44/blitz_api/blob/72862f8d6a25d0951097e6e3db79e4d0c10cca3f/app/api/utils.py#L57

This function returns an empty string when a key is not found in Redis. This is not good. An empty string could be a valid value for a key. The caller can get confused whether the result is an error or just an empty string.