Exception: PoliPage::Error

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

Overview

Base for all SDK-raised errors. Inherits from ‘StandardError` so that `rescue => e` catches it (whereas inheriting from `Exception` would bypass the default rescue and surprise callers).

The rescue-friendly path is the class hierarchy (‘rescue PoliPage::AuthenticationError`); the predicate methods below are kept for spec parity with the Node SDK and for callers who want a single rescue clause backed by introspection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code:, status: nil, request_id: nil) ⇒ Error

Returns a new instance of Error.



15
16
17
18
19
20
# File 'lib/poli_page/errors.rb', line 15

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



13
14
15
# File 'lib/poli_page/errors.rb', line 13

def code
  @code
end

#request_idObject (readonly)

Returns the value of attribute request_id.



13
14
15
# File 'lib/poli_page/errors.rb', line 13

def request_id
  @request_id
end

#statusObject (readonly)

Returns the value of attribute status.



13
14
15
# File 'lib/poli_page/errors.rb', line 13

def status
  @status
end

Instance Method Details

#auth_error?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/poli_page/errors.rb', line 22

def auth_error?
  is_a?(AuthenticationError) || is_a?(PermissionDeniedError)
end

#network_error?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/poli_page/errors.rb', line 34

def network_error?
  is_a?(ConnectionError) || is_a?(TimeoutError)
end

#payload_statusObject



59
60
61
# File 'lib/poli_page/errors.rb', line 59

def payload_status
  @status
end

#rate_limit_error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/poli_page/errors.rb', line 26

def rate_limit_error?
  is_a?(RateLimitError)
end

#retryable?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/poli_page/errors.rb', line 38

def retryable?
  return true if network_error?
  return true if status && (status >= 500 || status == 429)

  false
end

#to_payloadObject

Canonical wire payload for framework integrations: ‘message:, status:, request_id:`. `status` surfaces 503 for connection failures, 504 for timeouts, the API HTTP status for status-bearing errors. The #status reader itself stays nil for transport-error instances — only the payload surfaces 503/504.



50
51
52
53
54
55
56
57
# File 'lib/poli_page/errors.rb', line 50

def to_payload
  {
    code: @code,
    message: message,
    status: payload_status,
    request_id: @request_id
  }
end

#validation_error?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/poli_page/errors.rb', line 30

def validation_error?
  is_a?(ValidationError)
end