diff --git a/app/app.py b/app/app.py index b303839..a2c9497 100644 --- a/app/app.py +++ b/app/app.py @@ -1,11 +1,18 @@ import logging +import requests from logging.config import dictConfig +from flask import render_template from app.factory import create_app app = create_app() +@app.errorhandler(requests.exceptions.ConnectionError) +def request_connection_error(e): + return render_template('error.html'), 500 + + if __name__ == '__main__': app.run() gunicorn_logger = logging.getLogger('gunicorn.error') diff --git a/app/library/coingecko.py b/app/library/coingecko.py index 80dbeb4..b4bfb16 100644 --- a/app/library/coingecko.py +++ b/app/library/coingecko.py @@ -14,5 +14,5 @@ def get_market_data(coin_name='monero'): headers = {'accept': 'application/json'} url = f'https://api.coingecko.com/api/v3/coins/{coin_name}' current_app.logger.info(f'GET - {url}') - r = r_get(url, headers=headers, data=data) + r = r_get(url, timeout=8, headers=headers, data=data) return r.json() diff --git a/app/library/digitalocean.py b/app/library/digitalocean.py index e11a37d..9af35f0 100644 --- a/app/library/digitalocean.py +++ b/app/library/digitalocean.py @@ -14,11 +14,11 @@ class DigitalOcean(object): url = self.base + endpoint current_app.logger.info(f'{method.upper()} - {url}') if method == 'post': - r = requests.post(url, headers=self.headers, json=data) + r = requests.post(url, timeout=8, headers=self.headers, json=data) elif method == 'get': - r = requests.get(url, headers=self.headers) + r = requests.get(url, timeout=8, headers=self.headers) elif method == 'delete': - r = requests.delete(url, headers=self.headers) + r = requests.delete(url, timeout=8, headers=self.headers) else: return 'method not defined' r.raise_for_status() diff --git a/app/library/monero.py b/app/library/monero.py index 945651b..448db18 100644 --- a/app/library/monero.py +++ b/app/library/monero.py @@ -16,9 +16,11 @@ class WalletRPC(object): def make_wallet_rpc(self, method, params={}): r = requests.get( self.endpoint, + timeout=8, data=json.dumps({'method': method, 'params': params}), auth=self.auth ) + r.raise_for_status() current_app.logger.info(f'GET - {self.endpoint} - {method}') if 'error' in r.json(): return r.json()['error'] diff --git a/app/templates/error.html b/app/templates/error.html new file mode 100644 index 0000000..e9ed182 --- /dev/null +++ b/app/templates/error.html @@ -0,0 +1,23 @@ + + + + {% include 'includes/head.html' %} + + + + {% include 'includes/header.html' %} + +
+
+
+

Well dang, something broke.

+
+ Try Again +
+
+
+ + {% include 'includes/footer.html' %} + + +