Exception: Tinify::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/tinify/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, type = self.class.name.split("::").last, status = nil) ⇒ Error

Returns a new instance of Error.



19
20
21
# File 'lib/tinify/error.rb', line 19

def initialize(message, type = self.class.name.split("::").last, status = nil)
  @message, @type, @status = message, type, status
end

Instance Attribute Details

#status ⇒ Object (readonly)

Returns the value of attribute status.



17
18
19
# File 'lib/tinify/error.rb', line 17

def status
  @status
end

Class Method Details

.create(message, type, status) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/tinify/error.rb', line 4

def create(message, type, status)
  klass = case status
  when 401, 429 then AccountError
  when 400..499 then ClientError
  when 500..599 then ServerError
  else Error
  end

  message = "No message was provided" if message.to_s.empty?
  klass.new(message, type, status)
end

Instance Method Details

#message ⇒ Object Also known as: to_s



23
24
25
26
27
28
29
# File 'lib/tinify/error.rb', line 23

def message
  if status
    "#{@message} (HTTP #{@status}/#{@type})"
  else
    "#{@message}"
  end
end