Class: X::MediaProcessingCheckFailed

Inherits:
Uploads::Error show all
Defined in:
x-uploads/lib/x/uploads/media_processing_check_failed.rb

Overview

Error raised when media is uploaded, but a check of its processing fails

An upload awaits the processing of media X processes, such as a video, once the media is uploaded, so the media is not lost to a check that fails, as one the API answers with a server error, or one the on_response hook of the client raises: the error holds the media, which can be awaited again with await_processing. The error that failed the check is the cause, whose message the message ends with. A TokenReportFailed, which a check raises when save_tokens raised for the tokens of a refresh it made, is raised as it is, rather than as this error, so that the rescue of it that stores the tokens it holds catches it around an upload as around any other request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, media: nil) ⇒ MediaProcessingCheckFailed

Initialize the error with the media that was uploaded

The message is the one given, or else names the media by its identifier, when media that holds one was given.

Examples:

Raise the error for media whose processing could not be checked

raise X::MediaProcessingCheckFailed.new(media: media)

Raise the error with a message of its own, as a test stub may

raise X::MediaProcessingCheckFailed, "Processing could not be checked"

Parameters:

  • message (String, nil) (defaults to: nil) —

    the message, or nil for one that names the media

  • media (UploadedMedia, Hash{String => Object}, nil) (defaults to: nil) —

    the media that was uploaded, a Hash of which is held as uploaded media



69
70
71
72
# File 'x-uploads/lib/x/uploads/media_processing_check_failed.rb', line 69

def initialize(message = nil, media: nil)
  @media = media.is_a?(Hash) ? UploadedMedia.new(media) : media
  super(message || ["Media", media&.[]("id"), "was uploaded, but its processing could not be checked"].compact.join(" "))
end

Instance Attribute Details

#media ⇒ UploadedMedia? (readonly)

The media that was uploaded, as the upload response describes it

Examples:

Await the processing of the media again later

rescue X::MediaProcessingCheckFailed => e
  client.await_media_processing(e.media)

Returns:

  • (UploadedMedia, nil) —

    the uploaded media, or nil if none was given



54
55
56
# File 'x-uploads/lib/x/uploads/media_processing_check_failed.rb', line 54

def media
  @media
end

Instance Method Details

#to_s ⇒ String

The message, ending with why the processing could not be checked

It ends with the message of the error that failed the check, which is the cause, if there is one, whether the message was given or named the media.

Examples:

Read why the processing could not be checked

error.message # => "Media 7 was uploaded, but its processing could not be checked: Service Unavailable"

Returns:

  • (String) —

    the message



83
# File 'x-uploads/lib/x/uploads/media_processing_check_failed.rb', line 83

def to_s = [super, cause&.message].compact.join(": ")