Exception: Contentful::Management::Error

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

Overview

All errors raised by the contentful gem are either instances of Contentful::Management::Error or inherit from Contentful::Management::Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



8
9
10
11
12
13
14
15
16
# File 'lib/contentful/management/error.rb', line 8

def initialize(response)
  @response = response
  @error = {
    url: response.request.endpoint,
    message: response.error_message,
    details: response.raw.body.instance_variable_get(:@contents)
  }
  super @response.error_message
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/contentful/management/error.rb', line 6

def error
  @error
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/contentful/management/error.rb', line 6

def response
  @response
end

Class Method Details

.[](error_status_code) ⇒ Object

Shortcut for creating specialized error classes USAGE rescue Contentful::Management::Error



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/contentful/management/error.rb', line 20

def self.[](error_status_code)
  case error_status_code
  when 404
    NotFound
  when 400
    BadRequest
  when 403
    AccessDenied
  when 409
    Conflict
  when 401
    Unauthorized
  when 422
    UnprocessableEntity
  when 429
    RateLimitExceeded
  when 500
    ServerError
  when 503
    ServiceUnavailable
  else
    Error
  end
end