Exception: LicenseKit::ApiError

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, code:, message:, detail: nil, request_id: nil, timestamp: nil, body: nil) ⇒ ApiError

Returns a new instance of ApiError.



5
6
7
8
9
10
11
12
13
# File 'lib/licensekit/errors.rb', line 5

def initialize(status:, code:, message:, detail: nil, request_id: nil, timestamp: nil, body: nil)
  super(message)
  @status = status
  @code = code
  @detail = detail
  @request_id = request_id
  @timestamp = timestamp
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/licensekit/errors.rb', line 3

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/licensekit/errors.rb', line 3

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



3
4
5
# File 'lib/licensekit/errors.rb', line 3

def detail
  @detail
end

#request_idObject (readonly)

Returns the value of attribute request_id.



3
4
5
# File 'lib/licensekit/errors.rb', line 3

def request_id
  @request_id
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/licensekit/errors.rb', line 3

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



3
4
5
# File 'lib/licensekit/errors.rb', line 3

def timestamp
  @timestamp
end

Class Method Details

.from_response(status, body) ⇒ Object



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

def self.from_response(status, body)
  envelope = LicenseKit.parse_error_envelope(body)
  return new(status: status, code: "UNKNOWN_ERROR", message: "Request failed with status #{status}", body: body) if envelope.nil?

  meta = envelope["meta"] || {}
  new(
    status: status,
    code: envelope["error"]["code"],
    message: envelope["error"]["message"],
    detail: envelope["error"]["detail"],
    request_id: meta["request_id"],
    timestamp: meta["timestamp"],
    body: body
  )
end