add M_TOO_LARGE error code for uploading a too large file (#6151)

Fixes #6109
This commit is contained in:
Anshul Angaria 2019-10-08 18:25:16 +05:30 committed by Andrew Morgan
parent ea7d938bca
commit 474abf1eb6
2 changed files with 7 additions and 2 deletions

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

@ -0,0 +1 @@
Fix bug when uploading a large file: Synapse responds with `M_UNKNOWN` while it should be `M_TOO_LARGE` according to spec. Contributed by Anshul Angaria.

View File

@ -17,7 +17,7 @@ import logging
from twisted.web.server import NOT_DONE_YET from twisted.web.server import NOT_DONE_YET
from synapse.api.errors import SynapseError from synapse.api.errors import Codes, SynapseError
from synapse.http.server import ( from synapse.http.server import (
DirectServeResource, DirectServeResource,
respond_with_json, respond_with_json,
@ -56,7 +56,11 @@ class UploadResource(DirectServeResource):
if content_length is None: if content_length is None:
raise SynapseError(msg="Request must specify a Content-Length", code=400) raise SynapseError(msg="Request must specify a Content-Length", code=400)
if int(content_length) > self.max_upload_size: if int(content_length) > self.max_upload_size:
raise SynapseError(msg="Upload request body is too large", code=413) raise SynapseError(
msg="Upload request body is too large",
code=413,
errcode=Codes.TOO_LARGE,
)
upload_name = parse_string(request, b"filename", encoding=None) upload_name = parse_string(request, b"filename", encoding=None)
if upload_name: if upload_name: