Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 36885:9675147aec06
hgweb: send errors using new response API
Our slow march off of wsgirequest continues.
Differential Revision: https://phab.mercurial-scm.org/D2795
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 10 Mar 2018 18:51:32 -0800 |
parents | ccb70a77f746 |
children | 67fb0dca29bc |
comparison
equal
deleted
inserted
replaced
36884:ccb70a77f746 | 36885:9675147aec06 |
---|---|
12 import os | 12 import os |
13 | 13 |
14 from .common import ( | 14 from .common import ( |
15 ErrorResponse, | 15 ErrorResponse, |
16 HTTP_BAD_REQUEST, | 16 HTTP_BAD_REQUEST, |
17 HTTP_NOT_FOUND, | |
18 HTTP_OK, | 17 HTTP_OK, |
19 HTTP_SERVER_ERROR, | |
20 cspvalues, | 18 cspvalues, |
21 permhooks, | 19 permhooks, |
20 statusmessage, | |
22 ) | 21 ) |
23 | 22 |
24 from .. import ( | 23 from .. import ( |
25 encoding, | 24 encoding, |
26 error, | 25 error, |
415 else: | 414 else: |
416 wsgireq.respond(HTTP_OK, ctype) | 415 wsgireq.respond(HTTP_OK, ctype) |
417 return content | 416 return content |
418 | 417 |
419 except (error.LookupError, error.RepoLookupError) as err: | 418 except (error.LookupError, error.RepoLookupError) as err: |
420 wsgireq.respond(HTTP_NOT_FOUND, ctype) | |
421 msg = pycompat.bytestr(err) | 419 msg = pycompat.bytestr(err) |
422 if (util.safehasattr(err, 'name') and | 420 if (util.safehasattr(err, 'name') and |
423 not isinstance(err, error.ManifestLookupError)): | 421 not isinstance(err, error.ManifestLookupError)): |
424 msg = 'revision not found: %s' % err.name | 422 msg = 'revision not found: %s' % err.name |
425 return tmpl('error', error=msg) | 423 |
426 except (error.RepoError, error.RevlogError) as inst: | 424 res.status = '404 Not Found' |
427 wsgireq.respond(HTTP_SERVER_ERROR, ctype) | 425 res.headers['Content-Type'] = ctype |
428 return tmpl('error', error=pycompat.bytestr(inst)) | 426 res.setbodygen(tmpl('error', error=msg)) |
429 except ErrorResponse as inst: | 427 return res.sendresponse() |
430 wsgireq.respond(inst, ctype) | 428 except (error.RepoError, error.RevlogError) as e: |
431 return tmpl('error', error=pycompat.bytestr(inst)) | 429 res.status = '500 Internal Server Error' |
430 res.headers['Content-Type'] = ctype | |
431 res.setbodygen(tmpl('error', error=pycompat.bytestr(e))) | |
432 return res.sendresponse() | |
433 except ErrorResponse as e: | |
434 res.status = statusmessage(e.code, pycompat.bytestr(e)) | |
435 res.headers['Content-Type'] = ctype | |
436 res.setbodygen(tmpl('error', error=pycompat.bytestr(e))) | |
437 return res.sendresponse() | |
432 | 438 |
433 def check_perm(self, rctx, req, op): | 439 def check_perm(self, rctx, req, op): |
434 for permhook in permhooks: | 440 for permhook in permhooks: |
435 permhook(rctx, req, op) | 441 permhook(rctx, req, op) |
436 | 442 |