summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <1342360+anoadragon453@users.noreply.github.com>2020-04-03 14:26:07 +0100
committerGitHub <noreply@github.com>2020-04-03 14:26:07 +0100
commit07b88c546de1b24f5cbc9b4cb6da98400a8155af (patch)
tree4d41c9f8cf0dc63696306c580bc67fd3d2327e78
parentReduce the number of calls to `resource.getrusage` (#7183) (diff)
downloadsynapse-07b88c546de1b24f5cbc9b4cb6da98400a8155af.tar.xz
Convert http.HTTPStatus objects to their int equivalent (#7188)
-rw-r--r--changelog.d/7188.misc1
-rw-r--r--synapse/api/errors.py9
2 files changed, 9 insertions, 1 deletions
diff --git a/changelog.d/7188.misc b/changelog.d/7188.misc
new file mode 100644
index 0000000000..f72955b95b
--- /dev/null
+++ b/changelog.d/7188.misc
@@ -0,0 +1 @@
+Fix consistency of HTTP status codes reported in log lines.
diff --git a/synapse/api/errors.py b/synapse/api/errors.py
index 11da016ac5..d54dfb385d 100644
--- a/synapse/api/errors.py
+++ b/synapse/api/errors.py
@@ -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