Skip to content

Commit da8be8d

Browse files
anoadragon453phil-flex
authored andcommitted
Convert http.HTTPStatus objects to their int equivalent (matrix-org#7188)
1 parent 25cd3d2 commit da8be8d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

changelog.d/7188.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix consistency of HTTP status codes reported in log lines.

synapse/api/errors.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ class CodeMessageException(RuntimeError):
8686

8787
def __init__(self, code, msg):
8888
super(CodeMessageException, self).__init__("%d: %s" % (code, msg))
89-
self.code = code
89+
90+
# Some calls to this method pass instances of http.HTTPStatus for `code`.
91+
# While HTTPStatus is a subclass of int, it has magic __str__ methods
92+
# which emit `HTTPStatus.FORBIDDEN` when converted to a str, instead of `403`.
93+
# This causes inconsistency in our log lines.
94+
#
95+
# To eliminate this behaviour, we convert them to their integer equivalents here.
96+
self.code = int(code)
9097
self.msg = msg
9198

9299

0 commit comments

Comments
 (0)