indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Our slow march off of wsgirequest continues.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2795

AFFECTED FILES
  mercurial/hgweb/hgweb_mod.py

CHANGE DETAILS

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -14,11 +14,10 @@
 from .common import (
     ErrorResponse,
     HTTP_BAD_REQUEST,
-    HTTP_NOT_FOUND,
     HTTP_OK,
-    HTTP_SERVER_ERROR,
     cspvalues,
     permhooks,
+    statusmessage,
 )
 
 from .. import (
@@ -417,18 +416,25 @@
                     return content
 
         except (error.LookupError, error.RepoLookupError) as err:
-            wsgireq.respond(HTTP_NOT_FOUND, ctype)
             msg = pycompat.bytestr(err)
             if (util.safehasattr(err, 'name') and
                 not isinstance(err,  error.ManifestLookupError)):
                 msg = 'revision not found: %s' % err.name
-            return tmpl('error', error=msg)
-        except (error.RepoError, error.RevlogError) as inst:
-            wsgireq.respond(HTTP_SERVER_ERROR, ctype)
-            return tmpl('error', error=pycompat.bytestr(inst))
-        except ErrorResponse as inst:
-            wsgireq.respond(inst, ctype)
-            return tmpl('error', error=pycompat.bytestr(inst))
+
+            res.status = '404 Not Found'
+            res.headers['Content-Type'] = ctype
+            res.setbodygen(tmpl('error', error=msg))
+            return res.sendresponse()
+        except (error.RepoError, error.RevlogError) as e:
+            res.status = '500 Internal Server Error'
+            res.headers['Content-Type'] = ctype
+            res.setbodygen(tmpl('error', error=pycompat.bytestr(e)))
+            return res.sendresponse()
+        except ErrorResponse as e:
+            res.status = statusmessage(e.code, pycompat.bytestr(e))
+            res.headers['Content-Type'] = ctype
+            res.setbodygen(tmpl('error', error=pycompat.bytestr(e)))
+            return res.sendresponse()
 
     def check_perm(self, rctx, req, op):
         for permhook in permhooks:



To: indygreg, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to