Class: X::ChunkedUploadFailed

Inherits:
Uploader::Error show all
Defined in:
x-uploader/lib/x/uploader/chunked_upload_failed.rb

Overview

Error raised when a chunked upload is initialized, but its chunks cannot be appended or it cannot be finalized

The media is created, and its identifier given, once the upload is initialized, so the media is not lost to a chunk or a finalize that fails, as one the API answers with a server error, to media that can no longer be read, as a file deleted, closed, or shrunk once the upload was initialized cannot, or to any other error that ends the upload, as one the on_response hook of the client raises, or a thread for the chunks that cannot be started: the error holds the media the upload initialized, which names it by its identifier and its media key. The error that failed the upload is the cause, whose message the message ends with. A Timeout::Error, as Timeout.timeout raises around the upload, is raised as it is, so that a rescue of it still catches it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize the error with the media the upload initialized

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 upload could not be finished

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

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

raise X::ChunkedUploadFailed, "The upload could not be finished"

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 the upload initialized, a Hash of which is held as uploaded media



65
66
67
68
# File 'x-uploader/lib/x/uploader/chunked_upload_failed.rb', line 65

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

Instance Attribute Details

#media ⇒ UploadedMedia? (readonly)

The media the upload initialized, which names it by its identifier

Examples:

Read the identifier of the media an upload left unfinished

rescue X::ChunkedUploadFailed => e
  e.media.id # => 1880028106020515840

Returns:



50
51
52
# File 'x-uploader/lib/x/uploader/chunked_upload_failed.rb', line 50

def media
  @media
end

Instance Method Details

#to_s ⇒ String

The message, ending with why the upload could not be finished

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

Examples:

Read why the upload could not be finished

error.message # => "Media 7 was initialized, but its upload could not be finished: Service Unavailable"

Returns:

  • (String) —

    the message



79
# File 'x-uploader/lib/x/uploader/chunked_upload_failed.rb', line 79

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