Class: Kameleoon::Events::HttpRequestFailure

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/events/http_request_failure.rb

Overview

Describes the failure of an SDK HTTP request reported to HttpRequestHandler.

Defined Under Namespace

Modules: Reason

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, http_status, cause) ⇒ HttpRequestFailure

Returns a new instance of HttpRequestFailure.



55
56
57
58
59
# File 'lib/kameleoon/events/http_request_failure.rb', line 55

def initialize(reason, http_status, cause)
  @reason = reason
  @http_status = http_status
  @cause = cause
end

Instance Attribute Details

#causeException? (readonly)

Returns The exception caused the failure. Not nil only if reason is Reason::EXCEPTION.

Returns:

  • (Exception, nil)

    The exception caused the failure. Not nil only if reason is Reason::EXCEPTION.



33
34
35
# File 'lib/kameleoon/events/http_request_failure.rb', line 33

def cause
  @cause
end

#http_statusInteger? (readonly)

Returns The HTTP status code of the response. Not nil only if reason is Reason::HTTP_STATUS.

Returns:

  • (Integer, nil)

    The HTTP status code of the response. Not nil only if reason is Reason::HTTP_STATUS.



29
30
31
# File 'lib/kameleoon/events/http_request_failure.rb', line 29

def http_status
  @http_status
end

#reasonSymbol (readonly)

Returns The reason of the failure, one of the Reason constants.

Returns:

  • (Symbol)

    The reason of the failure, one of the Reason constants.



25
26
27
# File 'lib/kameleoon/events/http_request_failure.rb', line 25

def reason
  @reason
end

Class Method Details

.from_exception(cause) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
# File 'lib/kameleoon/events/http_request_failure.rb', line 41

def self.from_exception(cause)
  new(Reason::EXCEPTION, nil, cause)
end

.from_http_status(http_status) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/kameleoon/events/http_request_failure.rb', line 36

def self.from_http_status(http_status)
  new(Reason::HTTP_STATUS, http_status, nil)
end

.of_cancellationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/kameleoon/events/http_request_failure.rb', line 46

def self.of_cancellation
  new(Reason::CANCELLED, nil, nil)
end

Instance Method Details

#to_sObject



50
51
52
53
# File 'lib/kameleoon/events/http_request_failure.rb', line 50

def to_s
  "HttpRequestFailure{reason:#{@reason},http_status:#{@http_status || 'nil'}," \
    "cause:#{@cause.nil? ? 'nil' : @cause.class}}"
end