Module: Asherah::Error

Defined in:
lib/asherah/error.rb

Overview

Asherah Error converts the error code to error message

Constant Summary collapse

ConfigError =
Class.new(StandardError)
NotInitialized =
Class.new(StandardError)
AlreadyInitialized =
Class.new(StandardError)
GetSessionFailed =
Class.new(StandardError)
EncryptFailed =
Class.new(StandardError)
DecryptFailed =
Class.new(StandardError)
BadConfig =
Class.new(StandardError)
CODES =
{
  -100 => NotInitialized,
  -101 => AlreadyInitialized,
  -102 => GetSessionFailed,
  -103 => EncryptFailed,
  -104 => DecryptFailed,
  -105 => BadConfig
}.freeze

Class Method Summary collapse

Class Method Details

.check_result!(result, message) ⇒ Object

Raises:

  • (error_class)


23
24
25
26
27
28
# File 'lib/asherah/error.rb', line 23

def self.check_result!(result, message)
  return unless result.negative?

  error_class = Error::CODES.fetch(result, StandardError)
  raise error_class, "#{message} (#{result})"
end