Show More
@@ -25,6 +25,7 b' different error conditions.' | |||||
25 | """ |
|
25 | """ | |
26 |
|
26 | |||
27 | import functools |
|
27 | import functools | |
|
28 | from pyramid.httpexceptions import HTTPLocked | |||
28 |
|
29 | |||
29 |
|
30 | |||
30 | def _make_exception(kind, *args): |
|
31 | def _make_exception(kind, *args): | |
@@ -54,3 +55,14 b' RequirementException = functools.partial' | |||||
54 | UnhandledException = functools.partial(_make_exception, 'unhandled') |
|
55 | UnhandledException = functools.partial(_make_exception, 'unhandled') | |
55 |
|
56 | |||
56 | URLError = functools.partial(_make_exception, 'url_error') |
|
57 | URLError = functools.partial(_make_exception, 'url_error') | |
|
58 | ||||
|
59 | ||||
|
60 | class HTTPRepoLocked(HTTPLocked): | |||
|
61 | """ | |||
|
62 | Subclass of HTTPLocked response that allows to set the title and status | |||
|
63 | code via constructor arguments. | |||
|
64 | """ | |||
|
65 | def __init__(self, title, status_code=None, **kwargs): | |||
|
66 | self.code = status_code or HTTPLocked.code | |||
|
67 | self.title = title | |||
|
68 | super(HTTPRepoLocked, self).__init__(**kwargs) |
@@ -31,6 +31,7 b' from pyramid.wsgi import wsgiapp' | |||||
31 | from vcsserver import remote_wsgi, scm_app, settings, hgpatches |
|
31 | from vcsserver import remote_wsgi, scm_app, settings, hgpatches | |
32 | from vcsserver.echo_stub import remote_wsgi as remote_wsgi_stub |
|
32 | from vcsserver.echo_stub import remote_wsgi as remote_wsgi_stub | |
33 | from vcsserver.echo_stub.echo_app import EchoApp |
|
33 | from vcsserver.echo_stub.echo_app import EchoApp | |
|
34 | from vcsserver.exceptions import HTTPRepoLocked | |||
34 | from vcsserver.server import VcsServer |
|
35 | from vcsserver.server import VcsServer | |
35 |
|
36 | |||
36 | try: |
|
37 | try: | |
@@ -197,6 +198,9 b' class HTTPApplication(object):' | |||||
197 |
|
198 | |||
198 | self.config.add_view(self.hg_stream(), route_name='stream_hg') |
|
199 | self.config.add_view(self.hg_stream(), route_name='stream_hg') | |
199 | self.config.add_view(self.git_stream(), route_name='stream_git') |
|
200 | self.config.add_view(self.git_stream(), route_name='stream_git') | |
|
201 | self.config.add_view( | |||
|
202 | self.handle_vcs_exception, context=Exception, | |||
|
203 | custom_predicates=[self.is_vcs_exception]) | |||
200 |
|
204 | |||
201 | def wsgi_app(self): |
|
205 | def wsgi_app(self): | |
202 | return self.config.make_wsgi_app() |
|
206 | return self.config.make_wsgi_app() | |
@@ -317,6 +321,23 b' class HTTPApplication(object):' | |||||
317 | return app(environ, start_response) |
|
321 | return app(environ, start_response) | |
318 | return _git_stream |
|
322 | return _git_stream | |
319 |
|
323 | |||
|
324 | def is_vcs_exception(self, context, request): | |||
|
325 | """ | |||
|
326 | View predicate that returns true if the context object is a VCS | |||
|
327 | exception. | |||
|
328 | """ | |||
|
329 | return hasattr(context, '_vcs_kind') | |||
|
330 | ||||
|
331 | def handle_vcs_exception(self, exception, request): | |||
|
332 | if exception._vcs_kind == 'repo_locked': | |||
|
333 | # Get custom repo-locked status code if present. | |||
|
334 | status_code = request.headers.get('X-RC-Locked-Status-Code') | |||
|
335 | return HTTPRepoLocked( | |||
|
336 | title=exception.message, status_code=status_code) | |||
|
337 | ||||
|
338 | # Re-raise exception if we can not handle it. | |||
|
339 | raise exception | |||
|
340 | ||||
320 |
|
341 | |||
321 | class ResponseFilter(object): |
|
342 | class ResponseFilter(object): | |
322 |
|
343 |
General Comments 0
You need to be logged in to leave comments.
Login now