diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-11-14 12:25:39 +0100 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-11-14 12:25:39 +0100 |
commit | 2c27e86a0f0291a40d45b3da9e9773983d49c2ad (patch) | |
tree | 1b99303049f1a8c294e8255ea486b3252259376f /templating | |
parent | c951fe102a26f9c771df8320c16b5625a9ade5f9 (diff) |
Return templating-errors to the caller
Fixes #140
Diffstat (limited to 'templating')
-rwxr-xr-x | templating/templating.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/templating/templating.py b/templating/templating.py index 340c54b..832beab 100755 --- a/templating/templating.py +++ b/templating/templating.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3.4 -import requests +import requests,traceback from jinja2 import Template,Environment,FileSystemLoader import json @@ -39,10 +39,11 @@ class MyHandler(http.server.BaseHTTPRequestHandler): template = env.get_template(url) body = template.render(objects=objects, options=options).encode('UTF-8') self.send_response(200) - except: - body = "baaad\n".encode('UTF-8') + self.send_header('Cache-Control','max-age=30, s-maxage=5') + except Exception as err: + body = ("Templating of %s failed to render. Most likely due to an error in the template. Error transcript:\n\n%s\n----\n\n%s\n" % (url, err, traceback.format_exc())).encode('UTF-8') self.send_response(500) - self.send_header('Cache-Control','max-age=30, s-maxage=5') + self.send_header('Cache-Control','max-age=1, s-maxage=1') self.send_header('Content-Length', int(len(body))) self.end_headers() self.wfile.write(body) |