Properly raise an exception when the body exceeds the max size. (#9145)

...instead of just creating the exception object and doing nothing with it.
This commit is contained in:
Patrick Cloke 2021-01-18 10:21:42 -05:00 committed by GitHub
parent 02070c69fa
commit 2b467d0b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 2 deletions

1
changelog.d/9145.bugfix Normal file
View File

@ -0,0 +1 @@
Fix "UnboundLocalError: local variable 'length' referenced before assignment" errors when the response body exceeds the expected size. This bug was introduced in v1.25.0.

View File

@ -724,7 +724,7 @@ class SimpleHttpClient:
read_body_with_max_size(response, output_stream, max_size) read_body_with_max_size(response, output_stream, max_size)
) )
except BodyExceededMaxSize: except BodyExceededMaxSize:
SynapseError( raise SynapseError(
502, 502,
"Requested file is too large > %r bytes" % (max_size,), "Requested file is too large > %r bytes" % (max_size,),
Codes.TOO_LARGE, Codes.TOO_LARGE,

View File

@ -996,7 +996,7 @@ class MatrixFederationHttpClient:
logger.warning( logger.warning(
"{%s} [%s] %s", request.txn_id, request.destination, msg, "{%s} [%s] %s", request.txn_id, request.destination, msg,
) )
SynapseError(502, msg, Codes.TOO_LARGE) raise SynapseError(502, msg, Codes.TOO_LARGE)
except Exception as e: except Exception as e:
logger.warning( logger.warning(
"{%s} [%s] Error reading response: %s", "{%s} [%s] Error reading response: %s",