hgweb: returns 404 for unknow revision instead of 500 stable
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 31 Jan 2013 22:30:52 +0100
branchstable
changeset 18521 0af2fe7b3274
parent 18520 751135cca13c
child 18522 36549fa712da
hgweb: returns 404 for unknow revision instead of 500 I noticed that access to filtered revision returned HTTP 500 code (internal server error). Investigation shown that it was the case for unknown revision too. That wrong and we now properly return a 404 for revision not found.
mercurial/hgweb/hgweb_mod.py
tests/test-hgweb-commands.t
--- a/mercurial/hgweb/hgweb_mod.py	Thu Jan 31 01:44:29 2013 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Jan 31 22:30:52 2013 +0100
@@ -233,10 +233,10 @@
 
             return content
 
-        except error.LookupError, err:
+        except (error.LookupError, error.RepoLookupError), err:
             req.respond(HTTP_NOT_FOUND, ctype)
             msg = str(err)
-            if 'manifest' not in msg:
+            if util.safehasattr(err, 'name') and 'manifest' not in msg:
                 msg = 'revision not found: %s' % err.name
             return tmpl('error', error=msg)
         except (error.RepoError, error.RevlogError), inst:
--- a/tests/test-hgweb-commands.t	Thu Jan 31 01:44:29 2013 +0100
+++ b/tests/test-hgweb-commands.t	Thu Jan 31 22:30:52 2013 +0100
@@ -1392,4 +1392,33 @@
   $ grep Status search
   Status: 200 Script output follows\r (esc)
 
+proper status for filtered revision
+
+
+(missing rev)
+
+  $ PATH_INFO=/rev/5; export PATH_INFO
+  $ QUERY_STRING='style=raw'
+  $ python hgweb.cgi #> search
+  Status: 404 Not Found\r (esc)
+  ETag: *\r (glob) (esc)
+  Content-Type: text/plain; charset=ascii\r (esc)
+  \r (esc)
+  
+  error: unknown revision '5'
+
+
+
+(filtered rev)
+
+  $ PATH_INFO=/rev/4; export PATH_INFO
+  $ QUERY_STRING='style=raw'
+  $ python hgweb.cgi #> search
+  Status: 404 Not Found\r (esc)
+  ETag: *\r (glob) (esc)
+  Content-Type: text/plain; charset=ascii\r (esc)
+  \r (esc)
+  
+  error: unknown revision '4'
+
   $ cd ..