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

Commit

Permalink
Convert http.HTTPStatus objects to their int equivalent (#7188)
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 authored Apr 3, 2020
1 parent 0f05fd1 commit 07b88c5
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 07b88c5

Please sign in to comment.