summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db.py1
-rw-r--r--pastepy.py8
2 files changed, 7 insertions, 2 deletions
diff --git a/db.py b/db.py
index 5ccc336..7a74ecb 100644
--- a/db.py
+++ b/db.py
@@ -1,6 +1,7 @@
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Index, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relation, backref
+from sqlalchemy.orm.exc import NoResultFound
import settings
engine = create_engine(settings.db_path)
diff --git a/pastepy.py b/pastepy.py
index 1431d23..fdc4e26 100644
--- a/pastepy.py
+++ b/pastepy.py
@@ -120,8 +120,12 @@ class Paste(object):
try:
cache = session.query(db.Cache).filter_by(paste_hash = hash).one()
paste = cache.paste
- except: # No cache found, generate it.
- paste = session.query(db.Paste).filter_by(hash = hash).one()
+ except db.NoResultFound: # No cache found, generate it.
+ try:
+ paste = session.query(db.Paste).filter_by(hash = hash).one()
+ except db.NoResultFound:
+ self.start_response('404 Not Found', [])
+ return []
try:
lexername, text = get_formatted(paste.syntax, paste.text if type(paste.text) == unicode else paste.text.decode('utf8'))
except: