Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
21 changes: 6 additions & 15 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,28 +821,19 @@ async def _do_send_invite(
},
)
except HttpResponseException as e:
if e.code in [400, 404]:
err = e.to_synapse_error()

# If we receive an error response that isn't a generic error, we
# assume that the remote understands the v2 invite API and this
# is a legitimate error.
if err.errcode != Codes.UNKNOWN:
raise err

# Otherwise, we assume that the remote server doesn't understand
# the v2 invite API. That's ok provided the room uses old-style event
# IDs.
# If an error is received that is due to an unrecognised endpoint,
# fallback to the v1 endpoint if the room uses old-style event IDs.
# Otherwise consider it a legitmate error and raise.
err = e.to_synapse_error()
if self._is_unknown_endpoint(e, err):
if room_version.event_format != EventFormatVersions.V1:
raise SynapseError(
400,
"User's homeserver does not support this room version",
Codes.UNSUPPORTED_ROOM_VERSION,
)
elif e.code in (403, 429):
raise e.to_synapse_error()
else:
raise
raise err

# Didn't work, try v1 API.
# Note the v1 API returns a tuple of `(200, content)`
Expand Down