Exception: Seekmodo::Sdk::ClientError

Inherits:
SeekmodoError show all
Defined in:
lib/seekmodo/sdk/exceptions/client_error.rb

Constant Summary collapse

KIND_NOT_CONFIGURED =
"not_configured"
KIND_BREAKER_OPEN =
"breaker_open"
KIND_NETWORK =
"network"
KIND_TIMEOUT =
"timeout"
KIND_HTTP_4XX =
"http_4xx"
KIND_HTTP_5XX =
"http_5xx"
KIND_BAD_RESPONSE =
"bad_response"
KIND_SIGNATURE_MISMATCH =
"signature_mismatch"
KIND_RATE_LIMITED =
"rate_limited"
KIND_OVER_QUOTA =
"over_quota"
KIND_TENANT_UNAVAILABLE =
"tenant_unavailable"
TENANT_UNAVAILABLE_ERROR_CODES =
%w[
  tenant_paused tenant_not_found tenant_unknown tenant_suspended tenant_disabled
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, kind, status_code = 0, body: nil, cause: nil) ⇒ ClientError

Returns a new instance of ClientError.



26
27
28
29
30
31
32
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 26

def initialize(message, kind, status_code = 0, body: nil, cause: nil)
  super(message)
  @kind = kind
  @status_code = status_code
  @body = body || {}
  set_backtrace(cause&.backtrace) if cause
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



24
25
26
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 24

def body
  @body
end

#kindObject (readonly)

Returns the value of attribute kind.



24
25
26
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 24

def kind
  @kind
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



24
25
26
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 24

def status_code
  @status_code
end

Class Method Details

.classify_error_code(error_code) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 52

def self.classify_error_code(error_code)
  return nil if error_code.nil? || error_code.empty?

  if TENANT_UNAVAILABLE_ERROR_CODES.include?(error_code)
    return KIND_TENANT_UNAVAILABLE
  end
  return KIND_SIGNATURE_MISMATCH if error_code == "signature_mismatch"
  return KIND_RATE_LIMITED if error_code == "rate_limited"
  return KIND_OVER_QUOTA if %w[over_quota feature_not_in_plan].include?(error_code)

  nil
end

Instance Method Details

#error_codeObject



47
48
49
50
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 47

def error_code
  err = body["error"]
  err.is_a?(String) ? err : nil
end

#is_transient?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 34

def is_transient?
  [
    KIND_NETWORK,
    KIND_TIMEOUT,
    KIND_HTTP_5XX,
    KIND_TENANT_UNAVAILABLE
  ].include?(kind)
end

#should_fallback?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/seekmodo/sdk/exceptions/client_error.rb', line 43

def should_fallback?
  kind != KIND_HTTP_4XX
end