Exception: CyberSource::Authentication::Util::JWT::JWTException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/AuthenticationSDK/util/JWT/JWTExceptions.rb

Overview

Base JWT Exception Class

Provides enhanced exception handling for JWT-related operations with error chaining and detailed stack trace information.

Instance Method Summary collapse

Constructor Details

#initialize(message = '', cause = nil) ⇒ JWTException

Returns a new instance of JWTException.

Parameters:

  • message (String) (defaults to: '')

    Error message describing the exception

  • cause (Exception, nil) (defaults to: nil)

    Optional underlying cause of the error



14
15
16
17
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 14

def initialize(message = '', cause = nil)
  super(message)
  set_backtrace(cause.backtrace) if cause&.backtrace
end

Instance Method Details

#cause_chain_messagesArray<String>

Returns Error messages from all exceptions in the chain.

Returns:

  • (Array<String>)

    Error messages from all exceptions in the chain



50
51
52
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 50

def cause_chain_messages
  exception_chain.map(&:message)
end

#exception_chainArray<Exception>

Returns Array of exceptions in the chain.

Returns:

  • (Array<Exception>)

    Array of exceptions in the chain



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 32

def exception_chain
  chain = [self]
  current = cause

  while current
    chain << current
    current = current.cause
  end

  chain
end

#full_message(highlight: false, order: :top) ⇒ String

Returns Detailed error message with all causes.

Parameters:

  • highlight (Boolean) (defaults to: false)

    Whether to highlight the message

  • order (Symbol) (defaults to: :top)

    :top or :bottom, determines message order

Returns:

  • (String)

    Detailed error message with all causes



57
58
59
60
61
62
63
64
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 57

def full_message(highlight: false, order: :top, **)
  messages = exception_chain.each_with_index.map do |exception, index|
    prefix = index.zero? ? '' : 'Caused by: '
    "#{prefix}#{exception.class}: #{exception.message}"
  end

  order == :bottom ? messages.reverse.join("\n") : messages.join("\n")
end

#has_cause?Boolean

Returns True if a cause exception exists.

Returns:

  • (Boolean)

    True if a cause exception exists



20
21
22
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 20

def has_cause?
  !cause.nil?
end

#root_causeException

Returns The root cause of the exception chain.

Returns:

  • (Exception)

    The root cause of the exception chain



45
46
47
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 45

def root_cause
  exception_chain.last
end

#to_sString

Returns Exception string with cause information.

Returns:

  • (String)

    Exception string with cause information



25
26
27
28
29
# File 'lib/AuthenticationSDK/util/JWT/JWTExceptions.rb', line 25

def to_s
  return super unless has_cause?

  "#{super}\nCaused by: #{cause}"
end