Merge pull request #29796 from open-craft/chris/FAL-2728

feat: InvalidKeyError message changed to NotFound 404 message
This commit is contained in:
Jeremy Ristau
2022-01-28 10:29:13 -05:00
committed by GitHub
2 changed files with 8 additions and 6 deletions

View File

@@ -888,7 +888,10 @@ class ContentLibraryXBlockValidationTest(APITestCase):
endpoint.format(**endpoint_parameters),
)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.json(), {'detail': "Invalid XBlock key"})
msg = f"XBlock {endpoint_parameters.get('block_key')} does not exist, or you don't have permission to view it."
self.assertEqual(response.json(), {
'detail': msg,
})
def test_xblock_handler_invalid_key(self):
"""This endpoint is tested separately from the previous ones as it's not a DRF endpoint."""

View File

@@ -36,8 +36,7 @@ LX_BLOCK_TYPES_OVERRIDE = {
}
class InvalidNotFound(NotFound):
default_detail = "Invalid XBlock key"
invalid_not_found_fmt = "XBlock {usage_key} does not exist, or you don't have permission to view it."
def _block_type_overrides(request_args):
@@ -71,7 +70,7 @@ def block_metadata(request, usage_key_str):
try:
usage_key = UsageKey.from_string(usage_key_str)
except InvalidKeyError as e:
raise InvalidNotFound from e
raise NotFound(invalid_not_found_fmt.format(usage_key=usage_key_str)) from e
block = load_block(usage_key, request.user, block_type_overrides=_block_type_overrides(request.GET))
includes = request.GET.get("include", "").split(",")
@@ -97,7 +96,7 @@ def render_block_view(request, usage_key_str, view_name):
try:
usage_key = UsageKey.from_string(usage_key_str)
except InvalidKeyError as e:
raise InvalidNotFound from e
raise NotFound(invalid_not_found_fmt.format(usage_key=usage_key_str)) from e
block = load_block(usage_key, request.user, block_type_overrides=_block_type_overrides(request.GET))
fragment = _render_block_view(block, view_name, request.user)
@@ -122,7 +121,7 @@ def get_handler_url(request, usage_key_str, handler_name):
try:
usage_key = UsageKey.from_string(usage_key_str)
except InvalidKeyError as e:
raise InvalidNotFound from e
raise NotFound(invalid_not_found_fmt.format(usage_key=usage_key_str)) from e
handler_url = _get_handler_url(usage_key, handler_name, request.user, request.GET)
return Response({"handler_url": handler_url})