Class: DhanHQ::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/DhanHQ/core/error_handler.rb

Overview

Provides a minimal shim for surfacing validation and runtime errors.

Class Method Summary collapse

Class Method Details

.handle(error) ⇒ Object

Normalises the exception raised for various error types.

Parameters:

  • error (Dry::Validation::Result, StandardError)

Raises:

  • (RuntimeError)


10
11
12
13
14
15
16
17
# File 'lib/DhanHQ/core/error_handler.rb', line 10

def self.handle(error)
  case error
  when Dry::Validation::Result
    raise DhanHQ::ValidationError, "Invalid parameters: #{error.errors.to_h}"
  else
    raise DhanHQ::Error, error.message
  end
end