Exception: Leash::Error

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

Overview

Structured error type raised by every Leash SDK call site.

Mirrors ‘leash-sdk-ts/src/errors.ts` and Python’s ‘leash.errors.LeashError`. The `code` field is the stable machine-readable identifier consumers should switch on; `message` is the human-readable line; `action` and `see_also` are optional remediation hints.

Known codes (kept in sync with leash-sdk-ts):

- NO_API_KEY
- NO_REQUEST_SERVER_CONSTRUCT
- BROWSER_MODE_UNSUPPORTED
- UNAUTHORIZED
- NO_AUTH_CONTEXT
- INTEGRATION_NOT_ENABLED
- INTEGRATION_ERROR
- UPGRADE_REQUIRED
- PLAN_BLOCK
- CONNECTION_REQUIRED
- NETWORK_ERROR
- KEY_NOT_DECLARED
- INVALID_KEY
- SOURCE_RESYNC_FAILED
- ENV_FETCH_ERROR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code: nil, action: nil, see_also: nil, status: nil, cause: nil, connect_url: nil) ⇒ Error

Returns a new instance of Error.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/leash/errors.rb', line 30

def initialize(message, code: nil, action: nil, see_also: nil, status: nil,
               cause: nil, connect_url: nil)
  super(message)
  @message = message
  @code = code
  @action = action
  @see_also = see_also
  @status = status
  @cause = cause
  @connect_url = connect_url
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



28
29
30
# File 'lib/leash/errors.rb', line 28

def action
  @action
end

#causeObject (readonly)

Returns the value of attribute cause.



28
29
30
# File 'lib/leash/errors.rb', line 28

def cause
  @cause
end

#codeObject (readonly)

Returns the value of attribute code.



28
29
30
# File 'lib/leash/errors.rb', line 28

def code
  @code
end

#see_alsoObject (readonly)

Returns the value of attribute see_also.



28
29
30
# File 'lib/leash/errors.rb', line 28

def see_also
  @see_also
end

#statusObject (readonly)

Returns the value of attribute status.



28
29
30
# File 'lib/leash/errors.rb', line 28

def status
  @status
end

Instance Method Details

#connect_urlObject

Compatibility shim — the 0.3 surface exposed ‘connect_url`.



43
44
45
# File 'lib/leash/errors.rb', line 43

def connect_url
  @connect_url
end

#messageObject

Override ‘message` to return our stored value — avoids Exception#message falling back to `to_s` and recursing infinitely.



49
50
51
# File 'lib/leash/errors.rb', line 49

def message
  @message
end

#to_sObject



53
54
55
56
57
58
# File 'lib/leash/errors.rb', line 53

def to_s
  out = +"x #{@message}"
  out << "\n  Fix: #{@action}" if @action
  out << "\n  See: #{@see_also}" if @see_also
  out
end