Exception: Flowy::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/flowy/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, title: nil, detail: nil, meta: nil) ⇒ Error

Returns a new instance of Error.



19
20
21
22
23
24
25
# File 'lib/flowy/error.rb', line 19

def initialize(code:, title: nil, detail: nil, meta: nil)
  @code = code
  @title = title
  @detail = detail
  @meta = meta
  super(build_message(code, title, detail))
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/flowy/error.rb', line 4

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



4
5
6
# File 'lib/flowy/error.rb', line 4

def detail
  @detail
end

#metaObject (readonly)

Returns the value of attribute meta.



4
5
6
# File 'lib/flowy/error.rb', line 4

def meta
  @meta
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/flowy/error.rb', line 4

def title
  @title
end

Class Method Details

.initialize_from_failure(failure:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/flowy/error.rb', line 6

def self.initialize_from_failure(failure:)
  unless failure.is_a?(Flowy::Failure)
    raise ArgumentError, "Flowy::Error requires a Flowy::Failure instance, got #{failure.class}"
  end

  new(
    code: failure.error_code,
    title: failure.error_title,
    detail: failure.error_description,
    meta: failure.error_data
  )
end

Instance Method Details

#to_failureObject



27
28
29
30
31
32
33
34
# File 'lib/flowy/error.rb', line 27

def to_failure
  Flowy::Failure.new(
    error_code: code,
    error_data: meta || {},
    error_title: title,
    error_description: detail
  )
end

#to_hashObject



36
37
38
# File 'lib/flowy/error.rb', line 36

def to_hash
  to_failure.to_hash
end