summary refs log tree commit diff
path: root/synapse/api/errors.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-03-14 13:36:06 +0000
committerRichard van der Hoff <richard@matrix.org>2017-03-14 14:15:37 +0000
commit1d09586599a495e01bfb6b887b1a59419673600a (patch)
treeade906efdb9031b4f83ebf0c487bd6929388bb48 /synapse/api/errors.py
parentre-refactor exception heirarchy (diff)
downloadsynapse-1d09586599a495e01bfb6b887b1a59419673600a.tar.xz
Address review comments
- don't blindly proxy all HTTPRequestExceptions
- log unexpected exceptions at error
- avoid `isinstance`
- improve docs on `from_http_response_exception`
Diffstat (limited to 'synapse/api/errors.py')
-rw-r--r--synapse/api/errors.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/synapse/api/errors.py b/synapse/api/errors.py
index d5391a80cd..6fbd5d6876 100644
--- a/synapse/api/errors.py
+++ b/synapse/api/errors.py
@@ -94,6 +94,17 @@ class SynapseError(CodeMessageException):
     def from_http_response_exception(cls, err):
         """Make a SynapseError based on an HTTPResponseException
 
+        This is useful when a proxied request has failed, and we need to
+        decide how to map the failure onto a matrix error to send back to the
+        client.
+
+        An attempt is made to parse the body of the http response as a matrix
+        error. If that succeeds, the errcode and error message from the body
+        are used as the errcode and error message in the new synapse error.
+
+        Otherwise, the errcode is set to M_UNKNOWN, and the error message is
+        set to the reason code from the HTTP response.
+
         Args:
             err (HttpResponseException):
 
@@ -137,13 +148,11 @@ class UnrecognizedRequestError(SynapseError):
 
 class NotFoundError(SynapseError):
     """An error indicating we can't find the thing you asked for"""
-    def __init__(self, *args, **kwargs):
-        if "errcode" not in kwargs:
-            kwargs["errcode"] = Codes.NOT_FOUND
+    def __init__(self, msg="Not found", errcode=Codes.NOT_FOUND):
         super(NotFoundError, self).__init__(
             404,
-            "Not found",
-            **kwargs
+            msg,
+            errcode=errcode
         )