aboutsummaryrefslogtreecommitdiffstats
path: root/pasteme.py
diff options
context:
space:
mode:
authorCédric Picard <cedric.picard@efrei.net>2014-11-28 19:32:30 +0100
committerCédric Picard <cedric.picard@efrei.net>2014-11-28 19:32:30 +0100
commit3ef2cc7e71fc89b99baac73500757839aa21923f (patch)
tree4fa162fa36dba77bc0210e6b2da280a34dba460d /pasteme.py
parentf106195fbbf58d8dad3dfa80e92d165a7af229bc (diff)
downloadpasteme-3ef2cc7e71fc89b99baac73500757839aa21923f.tar.gz
pasteme-3ef2cc7e71fc89b99baac73500757839aa21923f.tar.bz2
pasteme-3ef2cc7e71fc89b99baac73500757839aa21923f.zip
Better error gestion with correct status code
Diffstat (limited to 'pasteme.py')
-rwxr-xr-xpasteme.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/pasteme.py b/pasteme.py
index 744b07c..f155502 100755
--- a/pasteme.py
+++ b/pasteme.py
@@ -25,7 +25,7 @@ def route_paste_post():
pid = identigen.generate(content)
except AttributeError as e:
print(e)
- return bottle.template('internal_error')
+ bottle.abort(500)
path = pathbase / pid
with path.open(mode='wb') as fd:
fd.write(content.encode('utf8'))
@@ -46,7 +46,7 @@ def route_paste_get(pid, pformat='colored'):
content = fd.read()
except IOError:
# use this template for all file based exception
- return bottle.template('not_found')
+ bottle.abort(404)
if pformat == 'colored':
try:
lexer = pygments.lexers.guess_lexer(content)
@@ -56,6 +56,14 @@ def route_paste_get(pid, pformat='colored'):
return bottle.template('paste', content=content)
return content
+@bottle.error(404)
+def error404(error):
+ return bottle.template("not_found")
+
+@bottle.error(500)
+def error500(error):
+ return bottle.template("internal_error")
+
if __name__ == '__main__':
print('I: Starting application with development server')
bottle.run(host='0.0.0.0', port=8080, debug=True, reloader=True)