diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py
index 66209c12b1f5bc84c5d426706c815b66d09fe2a9..47901f5dce6e74f85cd19f9ded866b6942887690 100644
--- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py
+++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py
@@ -48,7 +48,9 @@ def register_blueprints(app):
 
 def register_errorhandlers(app):
     def render_error(error):
-        return render_template("{0}.html".format(error.code)), error.code
+        # If a HTTPException, pull the `code` attribute; default to 500
+        error_code = getattr(error, 'code', 500)
+        return render_template("{0}.html".format(error_code)), error_code
     for errcode in [401, 404, 500]:
         app.errorhandler(errcode)(render_error)
     return None