Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/common.py @ 5561:22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Wed, 28 Nov 2007 08:38:42 -0800 |
parents | 12e4d9524951 |
children | d61fea133f2d |
line wrap: on
line diff
--- a/mercurial/hgweb/common.py Wed Nov 28 08:38:06 2007 -0800 +++ b/mercurial/hgweb/common.py Wed Nov 28 08:38:42 2007 -0800 @@ -6,7 +6,17 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, mimetypes +import errno, mimetypes, os + +class ErrorResponse(Exception): + def __init__(self, code, message=None): + Exception.__init__(self) + self.code = code + if message is None: + from httplib import responses + self.message = responses.get(code, 'Error') + else: + self.message = message def get_mtime(repo_path): store_path = os.path.join(repo_path, ".hg") @@ -40,9 +50,13 @@ req.header([('Content-type', ct), ('Content-length', str(os.path.getsize(path)))]) return file(path, 'rb').read() - except (TypeError, OSError): - # illegal fname or unreadable file - return "" + except TypeError: + raise ErrorResponse(500, 'illegal file name') + except OSError, err: + if err.errno == errno.ENOENT: + raise ErrorResponse(404) + else: + raise ErrorResponse(500, err.strerror) def style_map(templatepath, style): """Return path to mapfile for a given style.