##// END OF EJS Templates
errorpages: add appenlight to pyramid layer
dan -
r194:bc4667ad default
parent child Browse files
Show More
@@ -168,7 +168,7 b' def webob_to_pyramid_http_response(webob'
168 return pyramid_response
168 return pyramid_response
169
169
170
170
171 def error_handler(exc, request):
171 def error_handler(exception, request):
172 # TODO: dan: replace the old pylons error controller with this
172 # TODO: dan: replace the old pylons error controller with this
173 from rhodecode.model.settings import SettingsModel
173 from rhodecode.model.settings import SettingsModel
174 from rhodecode.lib.utils2 import AttributeDict
174 from rhodecode.lib.utils2 import AttributeDict
@@ -179,9 +179,14 b' def error_handler(exc, request):'
179 log.exception('failed to fetch settings')
179 log.exception('failed to fetch settings')
180 rc_config = {}
180 rc_config = {}
181
181
182 base_response = HTTPInternalServerError()
183 # prefer original exception for the response since it may have headers set
184 if isinstance(exception, HTTPError):
185 base_response = exception
186
182 c = AttributeDict()
187 c = AttributeDict()
183 c.error_message = exc.status
188 c.error_message = base_response.status
184 c.error_explanation = exc.explanation or str(exc)
189 c.error_explanation = base_response.explanation or str(base_response)
185 c.visual = AttributeDict()
190 c.visual = AttributeDict()
186
191
187 c.visual.rhodecode_support_url = (
192 c.visual.rhodecode_support_url = (
@@ -189,15 +194,10 b' def error_handler(exc, request):'
189 request.route_url('rhodecode_support')
194 request.route_url('rhodecode_support')
190 )
195 )
191 c.redirect_time = 0
196 c.redirect_time = 0
192 c.rhodecode_name = rc_config.get('rhodecode_title')
197 c.rhodecode_name = rc_config.get('rhodecode_title', '')
193 if not c.rhodecode_name:
198 if not c.rhodecode_name:
194 c.rhodecode_name = 'Rhodecode'
199 c.rhodecode_name = 'Rhodecode'
195
200
196 base_response = HTTPInternalServerError()
197 # prefer original exception for the response since it may have headers set
198 if isinstance(exc, HTTPError):
199 base_response = exc
200
201 response = render_to_response(
201 response = render_to_response(
202 '/errors/error_document.html', {'c': c}, request=request,
202 '/errors/error_document.html', {'c': c}, request=request,
203 response=base_response)
203 response=base_response)
@@ -208,6 +208,9 b' def error_handler(exc, request):'
208 def includeme(config):
208 def includeme(config):
209 settings = config.registry.settings
209 settings = config.registry.settings
210
210
211 if asbool(settings.get('appenlight', 'false')):
212 config.include('appenlight_client.ext.pyramid_tween')
213
211 # Includes which are required. The application would fail without them.
214 # Includes which are required. The application would fail without them.
212 config.include('pyramid_mako')
215 config.include('pyramid_mako')
213 config.include('pyramid_beaker')
216 config.include('pyramid_beaker')
@@ -247,6 +250,7 b' def includeme(config):'
247 if not vcs_server_enabled:
250 if not vcs_server_enabled:
248 pylons_app_as_view = DisableVCSPagesWrapper(pylons_app_as_view)
251 pylons_app_as_view = DisableVCSPagesWrapper(pylons_app_as_view)
249
252
253
250 def pylons_app_with_error_handler(context, request):
254 def pylons_app_with_error_handler(context, request):
251 """
255 """
252 Handle exceptions from rc pylons app:
256 Handle exceptions from rc pylons app:
@@ -273,7 +277,14 b' def includeme(config):'
273 # how to handle a request.
277 # how to handle a request.
274 config.add_notfound_view(pylons_app_with_error_handler)
278 config.add_notfound_view(pylons_app_with_error_handler)
275
279
276 config.add_view(error_handler, context=HTTPError) # exceptions in rc pyramid
280 if settings.get('debugtoolbar.enabled', False):
281 # if toolbar, then only http type exceptions get caught and rendered
282 ExcClass = HTTPError
283 else:
284 # if no toolbar, then any exception gets caught and rendered
285 ExcClass = Exception
286 config.add_view(error_handler, context=ExcClass)
287
277
288
278 def includeme_last(config):
289 def includeme_last(config):
279 """
290 """
@@ -314,6 +325,10 b' def wrap_app_in_wsgi_middlewares(pyramid'
314 pyramid_app = RoutesMiddleware(
325 pyramid_app = RoutesMiddleware(
315 pyramid_app, config.registry._pylons_compat_config['routes.map'])
326 pyramid_app, config.registry._pylons_compat_config['routes.map'])
316
327
328 if asbool(settings.get('appenlight', 'false')):
329 pyramid_app, _ = wrap_in_appenlight_if_enabled(
330 pyramid_app, config.registry._pylons_compat_config)
331
317 # TODO: johbo: Don't really see why we enable the gzip middleware when
332 # TODO: johbo: Don't really see why we enable the gzip middleware when
318 # serving static files, might be something that should have its own setting
333 # serving static files, might be something that should have its own setting
319 # as well?
334 # as well?
General Comments 0
You need to be logged in to leave comments. Login now