Class: X::MissingMediaData

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

Overview

Raised when a response of an upload holds none of the data it describes the media with

The API answers an upload, a status check, and a change of metadata with what it acted on, under the data of the response. A response that succeeded without it holds nothing an upload can go on, so the uploaders raise this rather than fail later on what is missing. A response that holds problems in place of the data, as one for media X does not know of does, names the reason in them, which the error holds, and names in its message.

It descends from X::Uploader::Error, and so from X::Error, so rescuing the failures of an upload catches it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, problems: []) ⇒ MissingMediaData

Initialize the error with the reason X gave for holding no data

The message is the one given, then the detail, or else the message or the title, of the first problem the response reported, as "The response of the status check holds no media: Could not find media".

Examples:

Raise the error for a response that holds problems in place of media

raise X::MissingMediaData.new("The response holds no media", problems: X::Problem.all_from(response))

Raise the error with a message alone, as a test stub may

raise X::MissingMediaData, "The response holds no media"

Parameters:

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

    the message, or nil for the reason alone

  • problems (Array<Problem>) (defaults to: []) —

    the problems the response reported in place of the data



38
39
40
41
42
43
# File 'x-uploader/lib/x/uploader/missing_media_data.rb', line 38

def initialize(message = nil, problems: [])
  @problems = problems.dup.freeze
  reason = problems.first&.then { |problem| problem.detail || problem.message || problem.title }
  parts = [message, reason].compact
  super((parts.join(": ") unless parts.empty?))
end

Instance Attribute Details

#problems ⇒ Array<Problem> (readonly)

The problems the response reported in place of the data

Examples:

Tell media X does not know of

error.problems.any?(&:not_found?)

Returns:

  • (Array<Problem>) —

    the problems, frozen, empty for a response that reported none



23
24
25
# File 'x-uploader/lib/x/uploader/missing_media_data.rb', line 23

def problems
  @problems
end