mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 06:29:27 -05:00
Merge pull request #4362 from matrix-org/erikj/better_errors
Use RequestSendFailed when fail to parse content type headers
This commit is contained in:
commit
d1d81d0651
1
changelog.d/4362.misc
Normal file
1
changelog.d/4362.misc
Normal file
@ -0,0 +1 @@
|
||||
Add better logging for unexpected errors while sending transactions
|
@ -823,21 +823,21 @@ def check_content_type_is_json(headers):
|
||||
headers (twisted.web.http_headers.Headers): headers to check
|
||||
|
||||
Raises:
|
||||
RuntimeError if the
|
||||
RequestSendFailed: if the Content-Type header is missing or isn't JSON
|
||||
|
||||
"""
|
||||
c_type = headers.getRawHeaders(b"Content-Type")
|
||||
if c_type is None:
|
||||
raise RuntimeError(
|
||||
raise RequestSendFailed(RuntimeError(
|
||||
"No Content-Type header"
|
||||
)
|
||||
), can_retry=False)
|
||||
|
||||
c_type = c_type[0].decode('ascii') # only the first header
|
||||
val, options = cgi.parse_header(c_type)
|
||||
if val != "application/json":
|
||||
raise RuntimeError(
|
||||
raise RequestSendFailed(RuntimeError(
|
||||
"Content-Type not application/json: was '%s'" % c_type
|
||||
)
|
||||
), can_retry=False)
|
||||
|
||||
|
||||
def encode_query_args(args):
|
||||
|
Loading…
Reference in New Issue
Block a user