##// END OF EJS Templates
errorpages: convert webob responses better, include status text + headers
dan -
r191:de2c66e3 default
parent child Browse files
Show More
@@ -158,6 +158,16 b' def add_pylons_compat_data(registry, glo'
158 registry._pylons_compat_settings = settings
158 registry._pylons_compat_settings = settings
159
159
160
160
161 def webob_to_pyramid_http_response(webob_response):
162 ResponseClass = httpexceptions.status_map[webob_response.status_int]
163 pyramid_response = ResponseClass(webob_response.status)
164 pyramid_response.status = webob_response.status
165 pyramid_response.headers.update(webob_response.headers)
166 if pyramid_response.headers['content-type'] == 'text/html':
167 pyramid_response.headers['content-type'] = 'text/html; charset=UTF-8'
168 return pyramid_response
169
170
161 def error_handler(exc, request):
171 def error_handler(exc, request):
162 # TODO: dan: replace the old pylons error controller with this
172 # TODO: dan: replace the old pylons error controller with this
163 from rhodecode.model.settings import SettingsModel
173 from rhodecode.model.settings import SettingsModel
@@ -237,7 +247,6 b' def includeme(config):'
237 if not vcs_server_enabled:
247 if not vcs_server_enabled:
238 pylons_app_as_view = DisableVCSPagesWrapper(pylons_app_as_view)
248 pylons_app_as_view = DisableVCSPagesWrapper(pylons_app_as_view)
239
249
240
241 def pylons_app_with_error_handler(context, request):
250 def pylons_app_with_error_handler(context, request):
242 """
251 """
243 Handle exceptions from rc pylons app:
252 Handle exceptions from rc pylons app:
@@ -248,8 +257,8 b' def includeme(config):'
248 try:
257 try:
249 response = pylons_app_as_view(context, request)
258 response = pylons_app_as_view(context, request)
250 if 400 <= response.status_int <= 599: # webob type error responses
259 if 400 <= response.status_int <= 599: # webob type error responses
251 ExcClass = httpexceptions.status_map[response.status_int]
260 return error_handler(
252 return error_handler(ExcClass(response.status), request)
261 webob_to_pyramid_http_response(response), request)
253 except HTTPError as e: # pyramid type exceptions
262 except HTTPError as e: # pyramid type exceptions
254 return error_handler(e, request)
263 return error_handler(e, request)
255
264
General Comments 0
You need to be logged in to leave comments. Login now