Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Propagate errors sensibly from proxied IS requests #2147
Conversation
dbkr
added some commits
Apr 21, 2017
| @@ -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) |
| +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 |
ara4n
Apr 21, 2017
Owner
I'm a bit confused - why can't we just pass the Matrix-style error response through to the client?
dbkr
Apr 21, 2017
Member
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. |
ara4n
assigned
dbkr
Apr 21, 2017
dbkr
assigned
ara4n
and unassigned
dbkr
Apr 21, 2017
dbkr
added some commits
Apr 21, 2017
dbkr
referenced this pull request
in matrix-org/sydent
Apr 21, 2017
Merged
Add support for rejecting sms reqs to countries #43
|
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. |
dbkr
assigned
erikjohnston
and unassigned
ara4n
Apr 25, 2017
|
Done - ptal |
dbkr
added some commits
Apr 26, 2017
dbkr
referenced this pull request
in vector-im/riot-web
Apr 26, 2017
Open
MSISDN registration should warn/error for unsupported countries #3542
| + errcode = jsonBody['errcode'] | ||
| + error = jsonBody['error'] | ||
| + return MatrixCodeMessageException(response.code, error, errcode) | ||
| + except: |
erikjohnston
May 2, 2017
Owner
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.
dbkr commentedApr 21, 2017
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 vector-im/riot-web#3542