-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Propagate errors sensibly from proxied IS requests #2147
Conversation
When we're proxying Matrix endpoints, parse out Matrix error responses and turn them into SynapseErrors so they can be propagated sensibly upstream.
synapse/http/client.py
Outdated
@@ -145,6 +145,9 @@ def post_json_get_json(self, uri, post_json): | |||
|
|||
body = yield preserve_context_over_fn(readBody, response) | |||
|
|||
if response.code / 100 != 2: | |||
raise CodeMessageException(response.code, body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really want to raise an exception on 300s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, yeah
synapse/http/client.py
Outdated
class MatrixProxyClient(object): | ||
""" | ||
An HTTP client that proxies other Matrix endpoints, ie. if the remote endpoint | ||
returns Matrix-style error response, this will raise the appropriate SynapseError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused - why can't we just pass the Matrix-style error response through to the client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we just want to indicate that an error has occurred, and since post_json_get_json just returns the body, previously we were masking the error status code and behaving as if the endpoint returned 2xx which confused things. The main thing is that we raise an exception on error responses, and if we turn it into a SynapseException then it just works without having to handle it specifically in all the different places.
looks plausible beyond the fact i think i'm entirely missing how this works :D might need slightly more of an explanation as to why turning a matrix error into a synapse error is actually the soln. |
What's the rationale here for not making the simple http client look for synapse style error messages? |
It seems pretty terrible for the HTTP client to look for any error responses that happen to have 'error' and 'errcode' keys in the response and interpret them without necessarily knowing what that means at the app protocol level. |
Having yet another HTTP client is going to be a bit confusing, I would have thought. There are two choices for doing this in The other option, that i think is probably nicer, is to add a subclass to try:
result = client.get_json(...)
...
except MatrixCodeMessageException as e:
raise e.as_synapse_error() # Converts the exception to SynapseError |
OK - I'd like to understand a bit better why more clients is going to be more confusing, but happy to change it back if you prefer. |
Parse json errors from get_json client methods and throw special errors.
Done - ptal |
synapse/http/client.py
Outdated
errcode = jsonBody['errcode'] | ||
error = jsonBody['error'] | ||
return MatrixCodeMessageException(response.code, error, errcode) | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally we prefer to list the types of exceptions, as otherwise its too easy to catch a typo or something. Its probably fine for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Changes in synapse v0.21.0 (2017-05-18) ======================================= No changes since v0.21.0-rc3 Changes in synapse v0.21.0-rc3 (2017-05-17) =========================================== Features: * Add per user rate-limiting overrides (PR matrix-org#2208) * Add config option to limit maximum number of events requested by ``/sync`` and ``/messages`` (PR matrix-org#2221) Thanks to @psaavedra! Changes: * Various small performance fixes (PR matrix-org#2201, matrix-org#2202, matrix-org#2224, matrix-org#2226, matrix-org#2227, matrix-org#2228, matrix-org#2229) * Update username availability checker API (PR matrix-org#2209, matrix-org#2213) * When purging, don't de-delta state groups we're about to delete (PR matrix-org#2214) * Documentation to check synapse version (PR matrix-org#2215) Thanks to @hamber-dick! * Add an index to event_search to speed up purge history API (PR matrix-org#2218) Bug fixes: * Fix API to allow clients to upload one-time-keys with new sigs (PR matrix-org#2206) Changes in synapse v0.21.0-rc2 (2017-05-08) =========================================== Changes: * Always mark remotes as up if we receive a signed request from them (PR matrix-org#2190) Bug fixes: * Fix bug where users got pushed for rooms they had muted (PR matrix-org#2200) Changes in synapse v0.21.0-rc1 (2017-05-08) =========================================== Features: * Add username availability checker API (PR matrix-org#2183) * Add read marker API (PR matrix-org#2120) Changes: * Enable guest access for the 3pl/3pid APIs (PR matrix-org#1986) * Add setting to support TURN for guests (PR matrix-org#2011) * Various performance improvements (PR matrix-org#2075, matrix-org#2076, matrix-org#2080, matrix-org#2083, matrix-org#2108, matrix-org#2158, matrix-org#2176, matrix-org#2185) * Make synctl a bit more user friendly (PR matrix-org#2078, matrix-org#2127) Thanks @APwhitehat! * Replace HTTP replication with TCP replication (PR matrix-org#2082, matrix-org#2097, matrix-org#2098, matrix-org#2099, matrix-org#2103, matrix-org#2014, matrix-org#2016, matrix-org#2115, matrix-org#2116, matrix-org#2117) * Support authenticated SMTP (PR matrix-org#2102) Thanks @DanielDent! * Add a counter metric for successfully-sent transactions (PR matrix-org#2121) * Propagate errors sensibly from proxied IS requests (PR matrix-org#2147) * Add more granular event send metrics (PR matrix-org#2178) Bug fixes: * Fix nuke-room script to work with current schema (PR matrix-org#1927) Thanks @zuckschwerdt! * Fix db port script to not assume postgres tables are in the public schema (PR matrix-org#2024) Thanks @jerrykan! * Fix getting latest device IP for user with no devices (PR matrix-org#2118) * Fix rejection of invites to unreachable servers (PR matrix-org#2145) * Fix code for reporting old verify keys in synapse (PR matrix-org#2156) * Fix invite state to always include all events (PR matrix-org#2163) * Fix bug where synapse would always fetch state for any missing event (PR matrix-org#2170) * Fix a leak with timed out HTTP connections (PR matrix-org#2180) * Fix bug where we didn't time out HTTP requests to ASes (PR matrix-org#2192) Docs: * Clarify doc for SQLite to PostgreSQL port (PR matrix-org#1961) Thanks @benhylau! * Fix typo in synctl help (PR matrix-org#2107) Thanks @HarHarLinks! * ``web_client_location`` documentation fix (PR matrix-org#2131) Thanks @matthewjwolff! * Update README.rst with FreeBSD changes (PR matrix-org#2132) Thanks @feld! * Clarify setting up metrics (PR matrix-org#2149) Thanks @encks!
When we're proxying Matrix endpoints, parse out Matrix error
responses and turn them into SynapseErrors so they can be
propagated sensibly upstream.
This will allow clients to give sensible error messages if the ID server rejects their request, for example element-hq/element-web#3542