diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py
index d348d171076d3966a4dd9db203e66b45a9b0a46f..a8f63a1cf9edefa4f309d6b5abc69e7c61cf914e 100644
--- a/addons/website/models/ir_http.py
+++ b/addons/website/models/ir_http.py
@@ -130,9 +130,9 @@ class ir_http(orm.AbstractModel):
             return super(ir_http, self)._handle_exception(exception)
         except Exception:
 
-        attach = self._serve_attachment()
-        if attach:
-            return attach
+            attach = self._serve_attachment()
+            if attach:
+                return attach
 
             if getattr(request, 'website_enabled', False) and request.website:
                 values = dict(