Class: OmniService::Error
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- OmniService::Error
- Defined in:
- lib/omni_service/error.rb
Overview
Structured validation/operation error.
Attributes:
-
component: the component that produced the error
-
code: symbolic error code (e.g., :blank, :not_found, :invalid)
-
message: human-readable message (optional)
-
path: array of keys/indices to error location (e.g., [:author, :email])
-
tokens: interpolation values for message templates (e.g., { min: 5 })
Components return failures that are converted to Error:
-
Failure(:code) => Error(code: :code)
-
Failure(“message”) => Error(message: “message”)
-
Failure({ code:, path:, message:, tokens: }) => Error(…)
-
Failure() => multiple Errors
Class Method Summary collapse
Class Method Details
.build(component) ⇒ Object
53 54 55 |
# File 'lib/omni_service/error.rb', line 53 def self.build(component, **) new(message: nil, code: nil, path: [], tokens: {}, **, component:) end |
.process(component, failure) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omni_service/error.rb', line 36 def self.process(component, failure) case failure in Array failure.flat_map { |error| process(component, error) } in OmniService::Error failure.new(component:) in String [build(component, message: failure)] in Symbol [build(component, code: failure)] in Hash [build(component, **failure)] else raise "Invalid failure `#{failure.inspect}` returned by `#{component.inspect}`" end end |