##// END OF EJS Templates
mercurial middleware now returns 500's instead of 404 on errors and 404 when repo not found, added tracebacks
marcink -
r334:6c23e724 default
parent child Browse files
Show More
@@ -2,6 +2,7 b''
2 2 # encoding: utf-8
3 3 # middleware to handle mercurial api calls
4 4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 from mercurial.error import RepoError
5 6
6 7 # This program is free software; you can redistribute it and/or
7 8 # modify it under the terms of the GNU General Public License
@@ -32,10 +33,11 b' from mercurial.hgweb.request import wsgi'
32 33 from paste.auth.basic import AuthBasicAuthenticator
33 34 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
34 35 from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware
35 from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache
36 from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache, \
37 check_repo_fast
36 38 from pylons_app.model import meta
37 39 from pylons_app.model.db import UserLog, User
38 from webob.exc import HTTPNotFound, HTTPForbidden
40 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
39 41 import logging
40 42 import os
41 43 import traceback
@@ -68,9 +70,9 b' class SimpleHg(object):'
68 70
69 71 try:
70 72 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:])
71 except Exception as e:
73 except:
72 74 log.error(traceback.format_exc())
73 return HTTPNotFound()(environ, start_response)
75 return HTTPInternalServerError()(environ, start_response)
74 76
75 77 #===================================================================
76 78 # CHECK PERMISSIONS FOR THIS REQUEST
@@ -83,7 +85,8 b' class SimpleHg(object):'
83 85 user = sa.query(User)\
84 86 .filter(User.username == username).one()
85 87 except:
86 return HTTPNotFound()(environ, start_response)
88 log.error(traceback.format_exc())
89 return HTTPInternalServerError()(environ, start_response)
87 90 #check permissions for this repository
88 91 if action == 'pull':
89 92 if not HasPermissionAnyMiddleware('repository.read',
@@ -110,11 +113,19 b' class SimpleHg(object):'
110 113 self.baseui = make_ui(self.config['hg_app_repo_conf'])
111 114 self.basepath = self.config['base_path']
112 115 self.repo_path = os.path.join(self.basepath, repo_name)
116
117 #quick check if that dir exists...
118 if check_repo_fast(repo_name, self.basepath):
119 return HTTPNotFound()(environ, start_response)
120
113 121 try:
114 122 app = wsgiapplication(self.__make_app)
123 except RepoError as e:
124 if str(e).find('not found') != -1:
125 return HTTPNotFound()(environ, start_response)
115 126 except Exception:
116 127 log.error(traceback.format_exc())
117 return HTTPNotFound()(environ, start_response)
128 return HTTPInternalServerError()(environ, start_response)
118 129
119 130
120 131 #invalidate cache on push
General Comments 0
You need to be logged in to leave comments. Login now