##// END OF EJS Templates
core: properly handle new redirections set in decorators....
marcink -
r1499:d130151d default
parent child Browse files
Show More
@@ -32,7 +32,7 b' from pyramid.config import Configurator'
32 32 from pyramid.settings import asbool, aslist
33 33 from pyramid.wsgi import wsgiapp
34 34 from pyramid.httpexceptions import (
35 HTTPError, HTTPInternalServerError, HTTPFound)
35 HTTPException, HTTPError, HTTPInternalServerError, HTTPFound)
36 36 from pyramid.events import ApplicationCreated
37 37 from pyramid.renderers import render_to_response
38 38 from routes.middleware import RoutesMiddleware
@@ -226,7 +226,7 b' def error_handler(exception, request):'
226 226
227 227 base_response = HTTPInternalServerError()
228 228 # prefer original exception for the response since it may have headers set
229 if isinstance(exception, HTTPError):
229 if isinstance(exception, HTTPException):
230 230 base_response = exception
231 231
232 232 def is_http_error(response):
@@ -1268,6 +1268,7 b' class NotAnonymous(object):'
1268 1268 return get_cython_compat_decorator(self.__wrapper, func)
1269 1269
1270 1270 def __wrapper(self, func, *fargs, **fkwargs):
1271 import rhodecode.lib.helpers as h
1271 1272 cls = fargs[0]
1272 1273 self.user = cls._rhodecode_user
1273 1274
@@ -1277,8 +1278,6 b' class NotAnonymous(object):'
1277 1278
1278 1279 if anonymous:
1279 1280 came_from = request.path_qs
1280
1281 import rhodecode.lib.helpers as h
1282 1281 h.flash(_('You need to be a registered user to '
1283 1282 'perform this action'),
1284 1283 category='warning')
@@ -1315,6 +1314,7 b' class HasAcceptedRepoType(object):'
1315 1314 return get_cython_compat_decorator(self.__wrapper, func)
1316 1315
1317 1316 def __wrapper(self, func, *fargs, **fkwargs):
1317 import rhodecode.lib.helpers as h
1318 1318 cls = fargs[0]
1319 1319 rhodecode_repo = cls.rhodecode_repo
1320 1320
@@ -1325,7 +1325,6 b' class HasAcceptedRepoType(object):'
1325 1325 if rhodecode_repo.alias in self.repo_type_list:
1326 1326 return func(*fargs, **fkwargs)
1327 1327 else:
1328 import rhodecode.lib.helpers as h
1329 1328 h.flash(h.literal(
1330 1329 _('Action not supported for %s.' % rhodecode_repo.alias)),
1331 1330 category='warning')
@@ -1349,7 +1348,7 b' class PermsDecorator(object):'
1349 1348 from pyramid.threadlocal import get_current_request
1350 1349 pyramid_request = get_current_request()
1351 1350 if not pyramid_request:
1352 # return global request of pylons incase pyramid one isn't available
1351 # return global request of pylons in case pyramid isn't available
1353 1352 return request
1354 1353 return pyramid_request
1355 1354
@@ -1360,6 +1359,7 b' class PermsDecorator(object):'
1360 1359 return _request.path_qs
1361 1360
1362 1361 def __wrapper(self, func, *fargs, **fkwargs):
1362 import rhodecode.lib.helpers as h
1363 1363 cls = fargs[0]
1364 1364 _user = cls._rhodecode_user
1365 1365
@@ -1375,7 +1375,6 b' class PermsDecorator(object):'
1375 1375 anonymous = _user.username == User.DEFAULT_USER
1376 1376
1377 1377 if anonymous:
1378 import rhodecode.lib.helpers as h
1379 1378 came_from = self._get_came_from()
1380 1379 h.flash(_('You need to be signed in to view this page'),
1381 1380 category='warning')
@@ -1970,3 +1969,5 b' def get_cython_compat_decorator(wrapper,'
1970 1969 return wrapper(func, *args, **kwds)
1971 1970 local_wrapper.__wrapped__ = func
1972 1971 return local_wrapper
1972
1973
@@ -21,7 +21,8 b''
21 21
22 22 import logging
23 23 from pyramid import httpexceptions
24 from pyramid.httpexceptions import HTTPError, HTTPInternalServerError
24 from pyramid.httpexceptions import (
25 HTTPRedirection, HTTPError, HTTPInternalServerError)
25 26 from pyramid.threadlocal import get_current_request
26 27
27 28 from rhodecode.lib.exceptions import VCSServerUnavailable
@@ -53,7 +54,7 b' class PylonsErrorHandlingMiddleware(obje'
53 54
54 55 def is_http_error(self, response):
55 56 # webob type error responses
56 return (400 <= response.status_int <= 599)
57 return 400 <= response.status_int <= 599
57 58
58 59 def reraise(self):
59 60 return self._reraise
@@ -73,9 +74,16 b' class PylonsErrorHandlingMiddleware(obje'
73 74 if self.is_http_error(response):
74 75 response = webob_to_pyramid_http_response(response)
75 76 return self.error_view(response, request)
76 except HTTPError as e: # pyramid type exceptions
77 except HTTPRedirection as e:
78 # pyramid type redirection, with status codes in the 300s
79 log.debug('Handling pyramid HTTPRedirection: %s', e)
80 return e
81 except HTTPError as e:
82 # pyramid type exceptions, with status codes in the 400s and 500s
83 log.debug('Handling pyramid HTTPError: %s', e)
77 84 return self.error_view(e, request)
78 85 except Exception as e:
86 log.debug('Handling general error: %s', e)
79 87
80 88 if self.reraise():
81 89 raise
@@ -89,6 +97,8 b' class PylonsErrorHandlingMiddleware(obje'
89 97
90 98
91 99 def webob_to_pyramid_http_response(webob_response):
100 log.debug('response is webob http error[%s], handling now...',
101 webob_response.status_int)
92 102 ResponseClass = httpexceptions.status_map[webob_response.status_int]
93 103 pyramid_response = ResponseClass(webob_response.status)
94 104 pyramid_response.status = webob_response.status
General Comments 0
You need to be logged in to leave comments. Login now