Patchwork D2795: hgweb: send errors using new response API

login
register
mail settings
Submitter phabricator
Date March 11, 2018, 5:24 a.m.
Message ID <differential-rev-PHID-DREV-spks46gzfadndws7u5ht-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/29286/
State Superseded
Headers show

Comments

phabricator - March 11, 2018, 5:24 a.m.
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




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

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: