Exception: Ghost::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, error_type: nil, context: nil, status_code: nil) ⇒ Error

Returns a new instance of Error.



7
8
9
10
11
12
# File 'lib/ghost/errors.rb', line 7

def initialize(message = nil, error_type: nil, context: nil, status_code: nil)
  @error_type = error_type
  @context = context
  @status_code = status_code
  super(message)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/ghost/errors.rb', line 5

def context
  @context
end

#error_typeObject (readonly)

Returns the value of attribute error_type.



5
6
7
# File 'lib/ghost/errors.rb', line 5

def error_type
  @error_type
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



5
6
7
# File 'lib/ghost/errors.rb', line 5

def status_code
  @status_code
end

Class Method Details

.from_response(status, body) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ghost/errors.rb', line 14

def self.from_response(status, body)
  error_class = ERROR_MAP[status] || Error
  errors = body.is_a?(Hash) && body["errors"] ? body["errors"] : []

  if errors.any?
    err = errors.first
    error_class.new(
      err["message"],
      error_type: err["type"],
      context: err["context"],
      status_code: status
    )
  else
    error_class.new("Unknown error", status_code: status)
  end
end