diff options
author | Cédric Picard <cedric.picard@efrei.net> | 2014-11-28 19:32:30 +0100 |
---|---|---|
committer | Cédric Picard <cedric.picard@efrei.net> | 2014-11-28 19:32:30 +0100 |
commit | 3ef2cc7e71fc89b99baac73500757839aa21923f (patch) | |
tree | 4fa162fa36dba77bc0210e6b2da280a34dba460d | |
parent | f106195fbbf58d8dad3dfa80e92d165a7af229bc (diff) | |
download | pasteme-3ef2cc7e71fc89b99baac73500757839aa21923f.tar.gz pasteme-3ef2cc7e71fc89b99baac73500757839aa21923f.tar.bz2 pasteme-3ef2cc7e71fc89b99baac73500757839aa21923f.zip |
Better error gestion with correct status code
-rwxr-xr-x | pasteme.py | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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) |