Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add missing errcode to parse_string and parse_boolean #11542

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11542.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing `errcode` to `parse_string` and `parse_boolean`.
4 changes: 2 additions & 2 deletions synapse/http/servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def parse_boolean_from_args(
message = (
"Boolean query parameter %r must be one of ['true', 'false']"
) % (name,)
raise SynapseError(400, message)
raise SynapseError(400, message, errcode=Codes.INVALID_PARAM)
else:
if required:
message = "Missing boolean query parameter %r" % (name,)
Expand Down Expand Up @@ -414,7 +414,7 @@ def _parse_string_value(
name,
", ".join(repr(v) for v in allowed_values),
)
raise SynapseError(400, message)
raise SynapseError(400, message, errcode=Codes.INVALID_PARAM)
else:
return value_str

Expand Down
4 changes: 2 additions & 2 deletions tests/rest/admin/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_invalid_parameter(self):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid search order
channel = self.make_request(
Expand All @@ -105,7 +105,7 @@ def test_invalid_parameter(self):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid destination
channel = self.make_request(
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/admin/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def test_invalid_parameter(self) -> None:
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
self.assertEqual(
"Boolean query parameter 'keep_profiles' must be one of ['true', 'false']",
channel.json_body["error"],
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/admin/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_invalid_parameter(self) -> None:
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# negative from
channel = self.make_request(
Expand Down
12 changes: 6 additions & 6 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def test_invalid_parameter(self):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid deactivated
channel = self.make_request(
Expand All @@ -618,7 +618,7 @@ def test_invalid_parameter(self):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# unkown order_by
channel = self.make_request(
Expand All @@ -628,7 +628,7 @@ def test_invalid_parameter(self):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid search order
channel = self.make_request(
Expand All @@ -638,7 +638,7 @@ def test_invalid_parameter(self):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

def test_limit(self):
"""
Expand Down Expand Up @@ -2896,7 +2896,7 @@ def test_invalid_parameter(self, method: str):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid search order
channel = self.make_request(
Expand All @@ -2906,7 +2906,7 @@ def test_invalid_parameter(self, method: str):
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# negative limit
channel = self.make_request(
Expand Down