Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 319b8b6

Browse files
author
David Robertson
authored
Name the type of token in "Invalid token" messages (#10815)
I had one of these error messages yesterday and assumed it was an invalid auth token (because that was an HTTP query parameter in the test) I was working on. In fact, it was an invalid next batch token for syncing.
1 parent 01c88a0 commit 319b8b6

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

changelog.d/10815.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Specify the type of token in generic "Invalid token" error messages.

synapse/handlers/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ async def validate_short_term_login_token(
13471347
try:
13481348
res = self.macaroon_gen.verify_short_term_login_token(login_token)
13491349
except Exception:
1350-
raise AuthError(403, "Invalid token", errcode=Codes.FORBIDDEN)
1350+
raise AuthError(403, "Invalid login token", errcode=Codes.FORBIDDEN)
13511351

13521352
await self.auth.check_auth_blocking(res.user_id)
13531353
return res

synapse/storage/relations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def from_string(string: str) -> "RelationPaginationToken":
7373
t, s = string.split("-")
7474
return RelationPaginationToken(int(t), int(s))
7575
except ValueError:
76-
raise SynapseError(400, "Invalid token")
76+
raise SynapseError(400, "Invalid relation pagination token")
7777

7878
def to_string(self) -> str:
7979
return "%d-%d" % (self.topological, self.stream)
@@ -103,7 +103,7 @@ def from_string(string: str) -> "AggregationPaginationToken":
103103
c, s = string.split("-")
104104
return AggregationPaginationToken(int(c), int(s))
105105
except ValueError:
106-
raise SynapseError(400, "Invalid token")
106+
raise SynapseError(400, "Invalid aggregation pagination token")
107107

108108
def to_string(self) -> str:
109109
return "%d-%d" % (self.count, self.stream)

synapse/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ async def parse(cls, store: "DataStore", string: str) -> "RoomStreamToken":
511511
)
512512
except Exception:
513513
pass
514-
raise SynapseError(400, "Invalid token %r" % (string,))
514+
raise SynapseError(400, "Invalid room stream token %r" % (string,))
515515

516516
@classmethod
517517
def parse_stream_token(cls, string: str) -> "RoomStreamToken":
@@ -520,7 +520,7 @@ def parse_stream_token(cls, string: str) -> "RoomStreamToken":
520520
return cls(topological=None, stream=int(string[1:]))
521521
except Exception:
522522
pass
523-
raise SynapseError(400, "Invalid token %r" % (string,))
523+
raise SynapseError(400, "Invalid room stream token %r" % (string,))
524524

525525
def copy_and_advance(self, other: "RoomStreamToken") -> "RoomStreamToken":
526526
"""Return a new token such that if an event is after both this token and
@@ -619,7 +619,7 @@ async def from_string(cls, store: "DataStore", string: str) -> "StreamToken":
619619
await RoomStreamToken.parse(store, keys[0]), *(int(k) for k in keys[1:])
620620
)
621621
except Exception:
622-
raise SynapseError(400, "Invalid Token")
622+
raise SynapseError(400, "Invalid stream token")
623623

624624
async def to_string(self, store: "DataStore") -> str:
625625
return self._SEPARATOR.join(

0 commit comments

Comments
 (0)