# HG changeset patch # User Gregory Szorc # Date 1520736692 28800 # Node ID 9675147aec0627d008c82ce2558c2bc083c52ef0 # Parent ccb70a77f74604f3633e3ffe8d97b1640564d374 hgweb: send errors using new response API Our slow march off of wsgirequest continues. Differential Revision: https://phab.mercurial-scm.org/D2795 diff -r ccb70a77f746 -r 9675147aec06 mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Sat Mar 10 18:42:00 2018 -0800 +++ b/mercurial/hgweb/hgweb_mod.py Sat Mar 10 18:51:32 2018 -0800 @@ -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: