Module: OmniService::Helpers

Defined in:
lib/omni_service/helpers.rb

Overview

Instance-level utility methods included via OmniService::Convenience.

Examples:

Converting external failures to OmniService errors

def call(params, **)
  result = external_service.validate(params)
  yield process_errors(result, path_prefix: [:external])
  # Failure from external becomes: [{ path: [:external, :field], code: :invalid }]
end

Instance Method Summary collapse

Instance Method Details

#process_errors(result, path_prefix: []) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/omni_service/helpers.rb', line 13

def process_errors(result, path_prefix: [])
  return result if result.success?

  Failure(OmniService::Error.process(self, result.failure).map do |error|
    error.new(path: [*path_prefix, *error.path])
  end)
end