fix: Catch a few errors

pull/12/head
Raphaël Vinot 2018-11-28 11:14:37 +01:00
parent b8e8cce57e
commit 4583228325
1 changed files with 6 additions and 2 deletions

View File

@ -6,7 +6,7 @@ try:
except ImportError:
import json
from flask import Flask, render_template, request, session, Response
from flask import Flask, render_template, request, session, Response, redirect, url_for
from flask_bootstrap import Bootstrap
from bgpranking.querying import Querying
@ -88,6 +88,8 @@ def index():
def asn_details():
load_session()
q = Querying()
if 'asn' not in session:
return redirect(url_for('/'))
asn_descriptions = q.get_asn_descriptions(asn=session['asn'], all_descriptions=True)
sources = q.get_sources(date=session['date'])
ranks = q.asn_details(**session)
@ -121,7 +123,9 @@ def asn_description():
def asn_history():
load_session()
q = Querying()
return Response(json.dumps(q.get_asn_history(**session)), mimetype='application/json')
if 'asn' in session:
return Response(json.dumps(q.get_asn_history(**session)), mimetype='application/json')
return Response(json.dumps({'error': f'asn key is required: {session}'}), mimetype='application/json')
@app.route('/country_history_callback', methods=['GET', 'POST'])