more logging, timeout for all requests, 500 error page

pull/1/head
lza_menace 4 years ago
parent 8b24da46f4
commit e7f1e045ce

@ -1,11 +1,18 @@
import logging import logging
import requests
from logging.config import dictConfig from logging.config import dictConfig
from flask import render_template
from app.factory import create_app from app.factory import create_app
app = create_app() app = create_app()
@app.errorhandler(requests.exceptions.ConnectionError)
def request_connection_error(e):
return render_template('error.html'), 500
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run()
gunicorn_logger = logging.getLogger('gunicorn.error') gunicorn_logger = logging.getLogger('gunicorn.error')

@ -14,5 +14,5 @@ def get_market_data(coin_name='monero'):
headers = {'accept': 'application/json'} headers = {'accept': 'application/json'}
url = f'https://api.coingecko.com/api/v3/coins/{coin_name}' url = f'https://api.coingecko.com/api/v3/coins/{coin_name}'
current_app.logger.info(f'GET - {url}') 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() return r.json()

@ -14,11 +14,11 @@ class DigitalOcean(object):
url = self.base + endpoint url = self.base + endpoint
current_app.logger.info(f'{method.upper()} - {url}') current_app.logger.info(f'{method.upper()} - {url}')
if method == 'post': 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': elif method == 'get':
r = requests.get(url, headers=self.headers) r = requests.get(url, timeout=8, headers=self.headers)
elif method == 'delete': elif method == 'delete':
r = requests.delete(url, headers=self.headers) r = requests.delete(url, timeout=8, headers=self.headers)
else: else:
return 'method not defined' return 'method not defined'
r.raise_for_status() r.raise_for_status()

@ -16,9 +16,11 @@ class WalletRPC(object):
def make_wallet_rpc(self, method, params={}): def make_wallet_rpc(self, method, params={}):
r = requests.get( r = requests.get(
self.endpoint, self.endpoint,
timeout=8,
data=json.dumps({'method': method, 'params': params}), data=json.dumps({'method': method, 'params': params}),
auth=self.auth auth=self.auth
) )
r.raise_for_status()
current_app.logger.info(f'GET - {self.endpoint} - {method}') current_app.logger.info(f'GET - {self.endpoint} - {method}')
if 'error' in r.json(): if 'error' in r.json():
return r.json()['error'] return r.json()['error']

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html>
{% include 'includes/head.html' %}
<body>
{% include 'includes/header.html' %}
<section class="hero is-primary">
<div class="hero-body">
<div class="container center">
<p>Well dang, something broke.</p>
<br />
<a href="{{ request.path }}">Try Again</a>
</div>
</div>
</section>
{% include 'includes/footer.html' %}
</body>
</html>
Loading…
Cancel
Save