forked from MirrorHub/synapse
Failover on proper error responses. (#14620)
When querying a remote server handle a 404/405 with an errcode of M_UNRECOGNIZED as an unimplemented endpoint.
This commit is contained in:
parent
cb59e08062
commit
9b6224577e
1
changelog.d/14620.bugfix
Normal file
1
changelog.d/14620.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Return spec-compliant JSON errors when unknown endpoints are requested.
|
|
@ -771,17 +771,28 @@ class FederationClient(FederationBase):
|
||||||
"""
|
"""
|
||||||
if synapse_error is None:
|
if synapse_error is None:
|
||||||
synapse_error = e.to_synapse_error()
|
synapse_error = e.to_synapse_error()
|
||||||
# There is no good way to detect an "unknown" endpoint.
|
# MSC3743 specifies that servers should return a 404 or 405 with an errcode
|
||||||
|
# of M_UNRECOGNIZED when they receive a request to an unknown endpoint or
|
||||||
|
# to an unknown method, respectively.
|
||||||
#
|
#
|
||||||
# Dendrite returns a 404 (with a body of "404 page not found");
|
# Older versions of servers don't properly handle this. This needs to be
|
||||||
# Conduit returns a 404 (with no body); and Synapse returns a 400
|
# rather specific as some endpoints truly do return 404 errors.
|
||||||
# with M_UNRECOGNIZED.
|
|
||||||
#
|
|
||||||
# This needs to be rather specific as some endpoints truly do return 404
|
|
||||||
# errors.
|
|
||||||
return (
|
return (
|
||||||
e.code == 404 and (not e.response or e.response == b"404 page not found")
|
# 404 is an unknown endpoint, 405 is a known endpoint, but unknown method.
|
||||||
) or (e.code == 400 and synapse_error.errcode == Codes.UNRECOGNIZED)
|
(e.code == 404 or e.code == 405)
|
||||||
|
and (
|
||||||
|
# Older Dendrites returned a text or empty body.
|
||||||
|
# Older Conduit returned an empty body.
|
||||||
|
not e.response
|
||||||
|
or e.response == b"404 page not found"
|
||||||
|
# The proper response JSON with M_UNRECOGNIZED errcode.
|
||||||
|
or synapse_error.errcode == Codes.UNRECOGNIZED
|
||||||
|
)
|
||||||
|
) or (
|
||||||
|
# Older Synapses returned a 400 error.
|
||||||
|
e.code == 400
|
||||||
|
and synapse_error.errcode == Codes.UNRECOGNIZED
|
||||||
|
)
|
||||||
|
|
||||||
async def _try_destination_list(
|
async def _try_destination_list(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Reference in a new issue