Skip to content

Commit

Permalink
include excepction in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
noamoss committed Jun 6, 2016
1 parent ba56f76 commit 0a8371d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 43 deletions.
8 changes: 0 additions & 8 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ def create_database(app):
db.session.commit()

app = create_app()

@app.errorhandler(404)
def not_found(error):
return render_template('404.html'), 404

@app.errorhandler(500)
def internal_error(error):
return render_template('500.html'), 500
4 changes: 2 additions & 2 deletions templates/500.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% extends "_base.html" %}

{% blcok content %}
{% block content %}

<h1>'משהו השתגע לנו'</h1>
<p> מסתבר שגם לציפור הקטנה יש בעיות בבסיס הנתונם. אנחנו עובדים לטפל בה, ממש עכשיו!
<br>
<a href="http:https://forum.hasadna.org.il/t/topic/1337" target="_blank">ספר/י לנו כאן</a>
איך זה קרה - על מה לחצת, מה כתבת, ואם אפשר - גם צילום מסך יעזור.
</p>
<p><a href = "{{urf_for('notifier.login')}}">בחזרה לקן</a></p>
<p><a href = "{{url_for('notifier.login')}}">בחזרה לקן</a></p>

{% endblock %}
4 changes: 2 additions & 2 deletions templates/502.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% extends "_base.html" %}

{% blcok content %}
{% block content %}

<h1>יש כאן בעיה</h1>
<p>הקישור למקור אינו תקין, אינו קיים, או שאינו בפורמט מוכר לנו
<br>
<a href="http:https://forum.hasadna.org.il/t/topic/1337" target="_blank">ספר/י לנו כאן</a>
איך זה קרה - על מה לחצת, מה כתבת, ואם אפשר - גם צילום מסך יעזור.

<p><a href = "{{urf_for('notifier.login')}}">בחזרה לקן</a></p>
<p><a href = "{{url_for('notifier.login')}}">בחזרה לקן</a></p>

{% endblock %}
15 changes: 15 additions & 0 deletions templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "_base.html" %}

{% block content %}

<h1>יש כאן בעיה</h1>
<p>
<br>
<a href="http:https://forum.hasadna.org.il/t/topic/1337" target="_blank">ספר/י לנו כאן</a>
איך זה קרה - על מה לחצת, מה כתבת, ואם אפשר - גם צילום מסך עם הוגעת השגיאה הזו, יעזור:
<br><br><hr>
{{ errormsg }}
<hr>
<p><a href = "{{url_for('notifier.login')}}">בחזרה לקן</a></p>

{% endblock %}
66 changes: 35 additions & 31 deletions views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# import the Flask class from the flask module
import datetime
import urllib

import datetime, urllib, sys
from functools import wraps

import flask_bcrypt as bcrypt
Expand Down Expand Up @@ -143,39 +143,44 @@ def add_feed_kikar():
def add_feed_opentaba():
url = request.args.get('link','')
relevantfeeds = relevant_feeds_urls()
if url not in relevantfeeds:
try:
city = request.args.get('city','')
except:
city=""

name = set_title_by_feed(url)[1]
try:
name_temp = name.split(" ")
try:
if url not in relevantfeeds:
try:
city = request.args.get('city','')
except:
city=""

name = set_title_by_feed(url)[1]
try:
name_temp = name.split(" ")
except:
name_temp = [name,"",""]
name_temp[2] = city+", "
name= " ".join(name_temp)
except:
pass
a_new_feed = Feed(
user_id=session['user_id'],
url = request.args.get('link',''),
name=name,
project='תב"ע פתוחה '+city,
)
db.session.add(a_new_feed)
db.session.commit()
flash(u'ההזנה החדשה נוספה למאגר')
return redirect(url_for('notifier.feeds_editor'))
else:
flash(u'את/ה כבר עוקבים אחרי מקור מידע זה')
return redirect(url_for('notifier.feeds_editor'))
a_new_feed = Feed(
user_id=session['user_id'],
url=request.args.get('link', ''),
name=name,
project='תב"ע פתוחה ' + city,
)
db.session.add(a_new_feed)
db.session.commit()
flash(u'ההזנה החדשה נוספה למאגר')
return redirect(url_for('notifier.feeds_editor'))

else:
flash(u'את/ה כבר עוקבים אחרי מקור מידע זה')
return redirect(url_for('notifier.feeds_editor'))

except (ValueError, KeyError, TypeError):
errormsg = "type: " + str(sys.exc_info()[0]) + ", value: " + str(sys.exc_info()[1]) + ", traceback: " + str(sys.exc_info()[2])
return render_template('error.html', errormsg=errormsg)


def login_user(user):
session['logged_in'] = True
session['user_id'] = user.id
session['user_email'] = user.email
flash(u'ברוכים הבאים, תהנו!')


@notifier.route('/add/<string:projectname>', methods=['GET','POST'])
Expand Down Expand Up @@ -315,15 +320,14 @@ def confirmed_email(token):
flash("אישרת את חשבונך, תודה!", "הצלחה")
return redirect(url_for('notifier.login'))

@notifier.app_errorhandler(500)
def internal_error(error):
return render_template('500.html'), 500


@notifier.app_errorhandler(404)
def not_found(error):
return render_template('404.html'), 404

@notifier.app_errorhandler(500)
def internal_error(error):
return render_template('500.html'), 500

@notifier.app_errorhandler(502)
def feed_error(error):
Expand Down

0 comments on commit 0a8371d

Please sign in to comment.