forked from MirrorHub/synapse
MSC 1866 - Use M_UNSUPPORTED_ROOM_VERSION for invite API
This commit is contained in:
parent
d14e94bae4
commit
59e0112209
2 changed files with 26 additions and 2 deletions
|
@ -33,6 +33,7 @@ from synapse.api.constants import (
|
||||||
)
|
)
|
||||||
from synapse.api.errors import (
|
from synapse.api.errors import (
|
||||||
CodeMessageException,
|
CodeMessageException,
|
||||||
|
Codes,
|
||||||
FederationDeniedError,
|
FederationDeniedError,
|
||||||
HttpResponseException,
|
HttpResponseException,
|
||||||
SynapseError,
|
SynapseError,
|
||||||
|
@ -792,10 +793,25 @@ class FederationClient(FederationBase):
|
||||||
defer.returnValue(content)
|
defer.returnValue(content)
|
||||||
except HttpResponseException as e:
|
except HttpResponseException as e:
|
||||||
if e.code in [400, 404]:
|
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.
|
||||||
|
|
||||||
if room_version in (RoomVersions.V1, RoomVersions.V2):
|
if room_version in (RoomVersions.V1, RoomVersions.V2):
|
||||||
pass # We'll fall through
|
pass # We'll fall through
|
||||||
else:
|
else:
|
||||||
raise Exception("Remote server is too old")
|
raise SynapseError(
|
||||||
|
400,
|
||||||
|
"User's homeserver does not support this room version",
|
||||||
|
Codes.UNSUPPORTED_ROOM_VERSION,
|
||||||
|
)
|
||||||
elif e.code == 403:
|
elif e.code == 403:
|
||||||
raise e.to_synapse_error()
|
raise e.to_synapse_error()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -25,9 +25,10 @@ from twisted.internet import defer
|
||||||
from twisted.internet.abstract import isIPAddress
|
from twisted.internet.abstract import isIPAddress
|
||||||
from twisted.python import failure
|
from twisted.python import failure
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes, Membership
|
from synapse.api.constants import KNOWN_ROOM_VERSIONS, EventTypes, Membership
|
||||||
from synapse.api.errors import (
|
from synapse.api.errors import (
|
||||||
AuthError,
|
AuthError,
|
||||||
|
Codes,
|
||||||
FederationError,
|
FederationError,
|
||||||
IncompatibleRoomVersionError,
|
IncompatibleRoomVersionError,
|
||||||
NotFoundError,
|
NotFoundError,
|
||||||
|
@ -386,6 +387,13 @@ class FederationServer(FederationBase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_invite_request(self, origin, content, room_version):
|
def on_invite_request(self, origin, content, room_version):
|
||||||
|
if room_version not in KNOWN_ROOM_VERSIONS:
|
||||||
|
raise SynapseError(
|
||||||
|
400,
|
||||||
|
"Homeserver does not support this room version",
|
||||||
|
Codes.UNSUPPORTED_ROOM_VERSION,
|
||||||
|
)
|
||||||
|
|
||||||
format_ver = room_version_to_event_format(room_version)
|
format_ver = room_version_to_event_format(room_version)
|
||||||
|
|
||||||
pdu = event_from_pdu_json(content, format_ver)
|
pdu = event_from_pdu_json(content, format_ver)
|
||||||
|
|
Loading…
Reference in a new issue