fix: Improve messaging, logging when adding Beta Library Content fails (#35707)

We have user-oriented messaging stuffed into the BadUpstream exception. We may
as well use it rather than just giving an opaque error about xblock references.

We also want to log this situation, since we'd expect that the library block
usage key that Studio provides should generally be valid. If it consistently
isn't, then that's an issue that operators are going to want to look into.
This commit is contained in:
Kyle McCormick
2024-10-23 08:31:29 -04:00
committed by GitHub
parent 4158a44307
commit af21100939

View File

@@ -594,9 +594,13 @@ def _create_block(request):
# Set `created_block.upstream` and then sync this with the upstream (library) version.
created_block.upstream = upstream_ref
sync_from_upstream(downstream=created_block, user=request.user)
except BadUpstream:
except BadUpstream as exc:
_delete_item(created_block.location, request.user)
return JsonResponse({"error": _("Invalid library xblock reference.")}, status=400)
log.exception(
f"Could not sync to new block at '{created_block.usage_key}' "
f"using provided library_content_key='{upstream_ref}'"
)
return JsonResponse({"error": str(exc)}, status=400)
modulestore().update_item(created_block, request.user.id)
return JsonResponse(