@@ -61,7 +61,6 @@ def _dispatch(self):
61
61
request .lang = request .context ['lang' ] = path .pop (1 )
62
62
path = '/' .join (path ) or '/'
63
63
return self .reroute (path )
64
- return self ._handle_exception (code = 404 )
65
64
return super (ir_http , self )._dispatch ()
66
65
67
66
def reroute (self , path ):
@@ -90,8 +89,8 @@ def _postprocess_args(self, arguments, rule):
90
89
try :
91
90
_ , path = rule .build (arguments )
92
91
assert path is not None
93
- except Exception :
94
- return self ._handle_exception (werkzeug . exceptions . NotFound () )
92
+ except Exception , e :
93
+ return self ._handle_exception (e , code = 404 )
95
94
96
95
if request .httprequest .method in ('GET' , 'HEAD' ):
97
96
generated_path = werkzeug .url_unquote_plus (path )
@@ -125,51 +124,66 @@ def _serve_attachment(self):
125
124
response .data = datas .decode ('base64' )
126
125
return response
127
126
128
- def _handle_exception (self , exception = None , code = 500 ):
129
- try :
127
+ def _handle_exception (self , exception , code = 500 ):
128
+ # This is done first as the attachment path may
129
+ # not match any HTTP controller, so the request
130
+ # may not be website-enabled.
131
+ attach = self ._serve_attachment ()
132
+ if attach :
133
+ return attach
134
+
135
+ is_website_request = bool (getattr (request , 'website_enabled' , False ) and request .website )
136
+ if not is_website_request :
137
+ # Don't touch non website requests exception handling
130
138
return super (ir_http , self )._handle_exception (exception )
131
- except Exception :
132
-
133
- attach = self ._serve_attachment ()
134
- if attach :
135
- return attach
136
-
137
- if getattr (request , 'website_enabled' , False ) and request .website :
138
- values = dict (
139
- exception = exception ,
140
- traceback = traceback .format_exc (exception ),
141
- )
142
- if exception :
143
- code = getattr (exception , 'code' , code )
144
- if isinstance (exception , ir_qweb .QWebException ):
145
- values .update (qweb_exception = exception )
146
- if isinstance (exception .qweb .get ('cause' ), openerp .exceptions .AccessError ):
147
- code = 403
148
- if code == 500 :
149
- logger .error ("500 Internal Server Error:\n \n %s" , values ['traceback' ])
150
- if 'qweb_exception' in values :
151
- view = request .registry .get ("ir.ui.view" )
152
- views = view ._views_get (request .cr , request .uid , exception .qweb ['template' ], request .context )
153
- to_reset = [v for v in views if v .model_data_id .noupdate is True ]
154
- values ['views' ] = to_reset
155
- elif code == 403 :
156
- logger .warn ("403 Forbidden:\n \n %s" , values ['traceback' ])
157
-
158
- values .update (
159
- status_message = werkzeug .http .HTTP_STATUS_CODES [code ],
160
- status_code = code ,
161
- )
162
-
163
- if not request .uid :
164
- self ._auth_method_public ()
165
-
166
- try :
167
- html = request .website ._render ('website.%s' % code , values )
168
- except Exception :
169
- html = request .website ._render ('website.http_error' , values )
170
- return werkzeug .wrappers .Response (html , status = code , content_type = 'text/html;charset=utf-8' )
171
-
172
- raise
139
+ else :
140
+ try :
141
+ response = super (ir_http , self )._handle_exception (exception )
142
+ if isinstance (response , Exception ):
143
+ exception = response
144
+ else :
145
+ # if parent excplicitely returns a plain response, then we don't touch it
146
+ return response
147
+ except Exception , e :
148
+ exception = e
149
+
150
+ values = dict (
151
+ exception = exception ,
152
+ traceback = traceback .format_exc (exception ),
153
+ )
154
+ code = getattr (exception , 'code' , code )
155
+
156
+ if isinstance (exception , openerp .exceptions .AccessError ):
157
+ code = 403
158
+
159
+ if isinstance (exception , ir_qweb .QWebException ):
160
+ values .update (qweb_exception = exception )
161
+ if isinstance (exception .qweb .get ('cause' ), openerp .exceptions .AccessError ):
162
+ code = 403
163
+
164
+ if code == 500 :
165
+ logger .error ("500 Internal Server Error:\n \n %s" , values ['traceback' ])
166
+ if 'qweb_exception' in values :
167
+ view = request .registry .get ("ir.ui.view" )
168
+ views = view ._views_get (request .cr , request .uid , exception .qweb ['template' ], request .context )
169
+ to_reset = [v for v in views if v .model_data_id .noupdate is True ]
170
+ values ['views' ] = to_reset
171
+ elif code == 403 :
172
+ logger .warn ("403 Forbidden:\n \n %s" , values ['traceback' ])
173
+
174
+ values .update (
175
+ status_message = werkzeug .http .HTTP_STATUS_CODES [code ],
176
+ status_code = code ,
177
+ )
178
+
179
+ if not request .uid :
180
+ self ._auth_method_public ()
181
+
182
+ try :
183
+ html = request .website ._render ('website.%s' % code , values )
184
+ except Exception :
185
+ html = request .website ._render ('website.http_error' , values )
186
+ return werkzeug .wrappers .Response (html , status = code , content_type = 'text/html;charset=utf-8' )
173
187
174
188
class ModelConverter (ir .ir_http .ModelConverter ):
175
189
def __init__ (self , url_map , model = False , domain = '[]' ):
0 commit comments