Exception: Tinplate::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/tinplate/errors.rb

Class Method Summary collapse

Class Method Details

.class_from_message(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tinplate/errors.rb', line 14

def self.class_from_message(message)
  case message
    when /503 Service Unavailable/          then Tinplate::ServiceUnavailableError
    when /service is busy due to high load/ then Tinplate::ServiceUnavailableError
    when /Image too simple/                 then Tinplate::NoSignatureError
    when /purchase another bundle/          then Tinplate::NoCreditsRemainingError
    when /Could not download/               then Tinplate::InaccessibleURLError
    when /Please supply an image/           then Tinplate::InvalidSearchError
    when /Error reading image data/         then Tinplate::InvalidImageDataError
    when /Too many concurrent requests/     then Tinplate::TooManyRequestsError
  end
end

.from_response(code, messages) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/tinplate/errors.rb', line 3

def self.from_response(code, messages)
  return UnauthorizedError.new(messages.first) if code == 403

  messages.each do |message|
    klass = class_from_message(message)
    return klass.new(messages.join("\n")) if klass
  end

  Tinplate::Error.new(messages.join("\n"))
end