Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconfirmed: Got response from sending SMS with no location header exception raised every time we send an SMS #438

Closed
DMRobertson opened this issue Oct 26, 2021 · 5 comments

Comments

@DMRobertson
Copy link
Contributor

Mypying spotted the following problem. But I can't see this behaviour in Sentry. That is odd. I don't understand the discrepancy and I'd like to.

In the following snippet:

  • getAllRawHeaders yields (bytes, List[bytes]). AFAICS it's done this since late 2015.

  • So headers: Dict[bytes, List[bytes]].

  • Therefore "X-Request-Id in headers" is False .

  • Therefore request_id is None and we never log a request ID.

  • Additionally, "Location" not in headers is True.

  • Therefore we should always raise on line 142.

headers = dict(resp.headers.getAllRawHeaders())
request_id = None
if "X-Request-Id" in headers:
request_id = headers["X-Request-Id"][0]
# Catch errors from the API. The documentation says a success code should be 202
# Accepted, but let's be broad here just in case and accept all 2xx response
# codes.
#
# Relevant OpenMarket API documentation:
# https://www.openmarket.com/docs/Content/apis/v4http/send-json.htm
if resp.code < 200 or resp.code >= 300:
if response_body is None or "error" not in response_body:
raise Exception(
"OpenMarket API responded with status %d (request ID: %s)"
% (
resp.code,
request_id,
),
)
error = response_body["error"]
raise Exception(
"OpenMarket API responded with status %d (request ID: %s): %s"
% (
resp.code,
request_id,
error,
),
)
if "Location" not in headers:
raise Exception("Got response from sending SMS with no location header")
# Nominally we should parse the URL, but we can just split on '/' since
# we only care about the last part.
parts = headers["Location"][0].split("/")
if len(parts) < 2:
raise Exception(
"Got response from sending SMS with malformed location header"
)
logger.info(
"Successfully sent SMS (ticket ID: %s, request ID %s), OpenMarket API"
" responded with code %d",
parts[-1],
request_id,
resp.code,
)

@DMRobertson
Copy link
Contributor Author

I don't think this causes any user visible problems, since we still send out the request. (I just think we'll fail to do any meaningful logging about the result.)

@DMRobertson
Copy link
Contributor Author

iweb.IResponse.headers and client.Response.headers are unannotated. I'm only seeing this now because I've added a stub which marks headers: Headers. And thankfully Headers is annotated.

@DMRobertson
Copy link
Contributor Author

DMRobertson commented Oct 26, 2021

I think we forgot to merge https://github.com/matrix-org/sydent/tree/release-v2.4 into main? See https://github.com/matrix-org/sydent/compare/release-v2.4 . I think main is missing the changes in #413 and #415.

@babolivier
Copy link
Contributor

I think we forgot to merge https://github.com/matrix-org/sydent/tree/release-v2.4 into main?

Ah yes that's probably the issue, let me do this

@babolivier
Copy link
Contributor

(done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants