Class: Gritz::Compat::Gruf::Error

Inherits:
Object
  • Object
show all
Defined in:
/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb

Defined Under Namespace

Classes: DebugInfo, Field

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Error

Returns a new instance of Error.



103
104
105
106
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 103

def initialize
  @field_errors = []
  @metadata = {}
end

Instance Attribute Details

#app_code ⇒ Object



100
101
102
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 100

def app_code
  @app_code
end

#code ⇒ Object



100
101
102
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 100

def code
  @code
end

#debug_info ⇒ Object (readonly)



101
102
103
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 101

def debug_info
  @debug_info
end

#field_errors ⇒ Object (readonly)



101
102
103
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 101

def field_errors
  @field_errors
end

#message ⇒ Object



100
101
102
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 100

def message
  @message
end

#metadata ⇒ Object



101
102
103
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 101

def 
  @metadata
end

Instance Method Details

#add_field_error(field, code, message = "") ⇒ Object



108
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 108

def add_field_error(field, code, message = "") = @field_errors << Field.new(field, code, message)

#fail!(_active_call = nil) ⇒ Object

Raises:



123
124
125
126
127
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 123

def fail!(_active_call = nil)
  canonical = { bad_request: :invalid_argument, unauthorized: :permission_denied }.fetch(code, code)
  trailers = .merge("error-internal-bin" => JSON.generate(to_h))
  raise Gritz::Errors.for_code(canonical).new(message, metadata: trailers)
end

#has_field_errors? ⇒ Boolean

rubocop:disable Naming/PredicatePrefix -- Preserve the upstream Gruf method name.

Returns:

  • (Boolean)


109
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 109

def has_field_errors? = !@field_errors.empty? # rubocop:disable Naming/PredicatePrefix -- Preserve the upstream Gruf method name.

#set_debug_info(detail, stack_trace = []) ⇒ Object



111
112
113
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 111

def set_debug_info(detail, stack_trace = [])
  @debug_info = DebugInfo.new(detail, stack_trace.is_a?(String) ? stack_trace.split("\n") : Array(stack_trace))
end

#to_h ⇒ Object



119
120
121
# File '/home/runner/work/gritz/gritz/sources/gritz-core/lib/gritz/compat/gruf.rb', line 119

def to_h
  { code:, app_code:, message:, field_errors: field_errors.map(&:to_h), debug_info: debug_info.to_h }
end