Skip to content

Commit

Permalink
Convert http.HTTPStatus objects to their int equivalent (matrix-org#7188
Browse files Browse the repository at this point in the history
)
  • Loading branch information
anoadragon453 authored and phil-flex committed Jun 16, 2020
1 parent 25cd3d2 commit da8be8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/7188.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix consistency of HTTP status codes reported in log lines.
9 changes: 8 additions & 1 deletion synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ class CodeMessageException(RuntimeError):

def __init__(self, code, msg):
super(CodeMessageException, self).__init__("%d: %s" % (code, msg))
self.code = code

# Some calls to this method pass instances of http.HTTPStatus for `code`.
# While HTTPStatus is a subclass of int, it has magic __str__ methods
# which emit `HTTPStatus.FORBIDDEN` when converted to a str, instead of `403`.
# This causes inconsistency in our log lines.
#
# To eliminate this behaviour, we convert them to their integer equivalents here.
self.code = int(code)
self.msg = msg


Expand Down

0 comments on commit da8be8d

Please sign in to comment.