# HG changeset patch # User Pierre-Yves David # Date 1510054587 -3600 # Node ID 3afe20410b553736f09100f2e5df93aeb1eaef4d # Parent aed2cac9edc3a95926053471d31a4464712a1d8a wireproto: gracefully fail on http when trying to use older pushkey method Previously the HTTP server would return a 500. It now returns a 410. diff -r aed2cac9edc3 -r 3afe20410b55 hgext3rd/evolve/obsexchange.py --- a/hgext3rd/evolve/obsexchange.py Tue Nov 07 12:10:22 2017 +0100 +++ b/hgext3rd/evolve/obsexchange.py Tue Nov 07 12:36:27 2017 +0100 @@ -27,6 +27,8 @@ wireproto, ) +from mercurial.hgweb import common as hgwebcommon + from . import ( exthelper, utility, @@ -197,14 +199,23 @@ abortmsg = "won't exchange obsmarkers through pushkey" hint = "upgrade your client or server to use the bundle2 protocol" +class HTTPCompatibleAbort(hgwebcommon.ErrorResponse, error.Abort): + def __init__(self, message, code, hint=None): + # initialisation of each class is a bit messy. + # We explicitly do the dispatch + hgwebcommon.ErrorResponse.__init__(self, 410, message) + error.Abort.__init__(self, message, hint=hint) + def forbidpushkey(repo=None, key=None, old=None, new=None): """prevent exchange through pushkey""" - raise error.Abort(abortmsg, hint=hint) + err = HTTPCompatibleAbort(abortmsg, 410, hint=hint) + raise err def forbidlistkey(repo=None, key=None, old=None, new=None): """prevent exchange through pushkey""" if obsolete.isenabled(repo, obsolete.exchangeopt): - raise error.Abort(abortmsg, hint=hint) + err = HTTPCompatibleAbort(abortmsg, 410, hint=hint) + raise err return {} @eh.uisetup diff -r aed2cac9edc3 -r 3afe20410b55 tests/test-wireproto.t --- a/tests/test-wireproto.t Tue Nov 07 12:10:22 2017 +0100 +++ b/tests/test-wireproto.t Tue Nov 07 12:36:27 2017 +0100 @@ -200,7 +200,7 @@ Check we cannot use pushkey for marker exchange anymore $ hg debugpushkey http://localhost:$HGPORT/ obsolete - abort: HTTP Error 500: Internal Server Error + abort: HTTP Error 410: won't exchange obsmarkers through pushkey [255] $ hg debugpushkey ssh://user@dummy/server obsolete remote: abort: won't exchange obsmarkers through pushkey