##// END OF EJS Templates
hgweb: send proper error messages to the client...
Sune Foldager -
r9694:8269fe2d default
parent child Browse files
Show More
@@ -31,8 +31,8 b' def _statusmessage(code):'
31 responses = BaseHTTPRequestHandler.responses
31 responses = BaseHTTPRequestHandler.responses
32 return responses.get(code, ('Error', 'Unknown error'))[0]
32 return responses.get(code, ('Error', 'Unknown error'))[0]
33
33
34 def statusmessage(code):
34 def statusmessage(code, message=None):
35 return '%d %s' % (code, _statusmessage(code))
35 return '%d %s' % (code, message or _statusmessage(code))
36
36
37 def get_mtime(repo_path):
37 def get_mtime(repo_path):
38 store_path = os.path.join(repo_path, ".hg")
38 store_path = os.path.join(repo_path, ".hg")
@@ -181,18 +181,19 b' def unbundle(repo, req):'
181 except ValueError, inst:
181 except ValueError, inst:
182 raise ErrorResponse(HTTP_OK, inst)
182 raise ErrorResponse(HTTP_OK, inst)
183 except (OSError, IOError), inst:
183 except (OSError, IOError), inst:
184 filename = getattr(inst, 'filename', '')
185 # Don't send our filesystem layout to the client
186 if filename.startswith(repo.root):
187 filename = filename[len(repo.root)+1:]
188 else:
189 filename = ''
190 error = getattr(inst, 'strerror', 'Unknown error')
184 error = getattr(inst, 'strerror', 'Unknown error')
191 if inst.errno == errno.ENOENT:
185 if inst.errno == errno.ENOENT:
192 code = HTTP_NOT_FOUND
186 code = HTTP_NOT_FOUND
193 else:
187 else:
194 code = HTTP_SERVER_ERROR
188 code = HTTP_SERVER_ERROR
195 raise ErrorResponse(code, '%s: %s' % (error, filename))
189 filename = getattr(inst, 'filename', '')
190 # Don't send our filesystem layout to the client
191 if filename and filename.startswith(repo.root):
192 filename = filename[len(repo.root)+1:]
193 text = '%s: %s' % (error, filename)
194 else:
195 text = error.replace(repo.root + os.path.sep, '')
196 raise ErrorResponse(code, text)
196 finally:
197 finally:
197 fp.close()
198 fp.close()
198 os.unlink(tempname)
199 os.unlink(tempname)
@@ -77,7 +77,7 b' class wsgirequest(object):'
77
77
78 if isinstance(status, ErrorResponse):
78 if isinstance(status, ErrorResponse):
79 self.header(status.headers)
79 self.header(status.headers)
80 status = statusmessage(status.code)
80 status = statusmessage(status.code, status.message)
81 elif status == 200:
81 elif status == 200:
82 status = '200 Script output follows'
82 status = '200 Script output follows'
83 elif isinstance(status, int):
83 elif isinstance(status, int):
General Comments 0
You need to be logged in to leave comments. Login now