-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display better error if Canvas Studio video cannot be used with Via #6233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,29 @@ | |
See `CanvasStudioService` for more details. | ||
""" | ||
|
||
from pyramid.httpexceptions import HTTPBadRequest, HTTPFound | ||
from pyramid.httpexceptions import HTTPFound | ||
from pyramid.view import view_config | ||
|
||
from lms.security import Permissions | ||
from lms.services import CanvasStudioService | ||
from lms.services.canvas_studio import replace_localhost_in_url | ||
from lms.services.exceptions import SerializableError | ||
from lms.validation.authentication import OAuthCallbackSchema | ||
from lms.views.helpers import via_video_url | ||
|
||
|
||
class CanvasStudioLaunchError(SerializableError): | ||
""" | ||
An error occurred while launching a Canvas Studio assignment. | ||
|
||
This exception is used for non-authorization errors that prevent a | ||
Canvas Studio assignment from being launched. | ||
""" | ||
|
||
def __init__(self, error_code: str, message: str): | ||
super().__init__(error_code=error_code, message=message) | ||
|
||
|
||
# View for authorization popup which redirects to Canvas Studio's OAuth | ||
# authorization endpoint. | ||
# | ||
|
@@ -135,15 +148,31 @@ def via_url(request): | |
document_url = assignment.document_url | ||
media_id = CanvasStudioService.media_id_from_url(document_url) | ||
if not media_id: | ||
raise HTTPBadRequest("Unable to get Canvas Studio media ID") | ||
raise CanvasStudioLaunchError( | ||
"canvas_studio_media_not_found", "Unable to get Canvas Studio media ID" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular error should never happen unless the document URL got edited on Canvas's side or we screwed up when generating it. However there is another related error which could happen, which is if the video gets removed in Canvas. I've used an error code which reflects that more general case. |
||
|
||
svc = request.find_service(CanvasStudioService) | ||
canonical_url = svc.get_canonical_video_url(media_id) | ||
|
||
# Get the video download URL, then the transcript. We do things in this | ||
# order because if the video cannot be used (eg. because it is a Vimeo | ||
# upload), there is no point in the user uploading a transcript, if that is | ||
# also missing. | ||
|
||
download_url = svc.get_video_download_url(media_id) | ||
transcript_url = svc.get_transcript_url(media_id) | ||
if not download_url: | ||
raise CanvasStudioLaunchError( | ||
"canvas_studio_download_unavailable", | ||
"Hypothesis was unable to fetch the video", | ||
) | ||
|
||
transcript_url = svc.get_transcript_url(media_id) | ||
if not transcript_url: | ||
raise HTTPBadRequest("This video does not have a published transcript") | ||
raise CanvasStudioLaunchError( | ||
"canvas_studio_transcript_unavailable", | ||
"This video does not have a published transcript", | ||
) | ||
|
||
return { | ||
"via_url": via_video_url(request, canonical_url, download_url, transcript_url) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something slightly confusing about these error messages is the fact that what you see here is not the entire message. Instead the server-provided message is shown at the top, and the children of the
ErrorModal
are shown underneath.For some of these errors, the server-side response includes only a code, for others there is a code and a message. Here I followed the pattern of those errors which include a short summary in the response, and then include extra details as
ErrorModal
children.If we want to translate these error messages in future, then we'll need to have them all in one place though.