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

Convert http.HTTPStatus objects to their int equivalent #7188

Merged
merged 6 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
10 changes: 9 additions & 1 deletion synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ 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.
# TODO: Clean up all calls to this method such that this type cast isn't needed
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
self.code = int(code)
self.msg = msg


Expand Down