Class: Gruf::Error
Overview
Represents a error that can be transformed into a gRPC error and have metadata attached to the trailing headers. This layer acts as an middle layer that can have metadata injection, tracing support, and other functionality not present in the gRPC core.
Constant Summary collapse
- TYPES =
{ ok: GRPC::Ok, cancelled: GRPC::Cancelled, unknown: GRPC::Unknown, invalid_argument: GRPC::InvalidArgument, bad_request: GRPC::InvalidArgument, deadline_exceeded: GRPC::DeadlineExceeded, not_found: GRPC::NotFound, already_exists: GRPC::AlreadyExists, unauthorized: GRPC::PermissionDenied, permission_denied: GRPC::PermissionDenied, unauthenticated: GRPC::Unauthenticated, resource_exhausted: GRPC::ResourceExhausted, failed_precondition: GRPC::FailedPrecondition, aborted: GRPC::Aborted, out_of_range: GRPC::OutOfRange, unimplemented: GRPC::Unimplemented, internal: GRPC::Internal, unavailable: GRPC::Unavailable, data_loss: GRPC::DataLoss }.freeze
Instance Attribute Summary collapse
-
#app_code ⇒ Object
Returns the value of attribute app_code.
-
#code ⇒ Object
Returns the value of attribute code.
-
#debug_info ⇒ Object
Returns the value of attribute debug_info.
-
#field_errors ⇒ Object
Returns the value of attribute field_errors.
- #grpc_error ⇒ GRPC::BadStatus
-
#message ⇒ Object
Returns the value of attribute message.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#add_field_error(field_name, error_code, message = '') ⇒ Object
Add a field error to this error package.
- #attach_to_call(active_call) ⇒ Error
- #fail!(active_call) ⇒ GRPC::BadStatus
-
#initialize(args = {}) ⇒ Error
constructor
Initialize the error, setting default values.
-
#serialize ⇒ String
Serialize the error for transport.
- #set_debug_info(detail, stack_trace = []) ⇒ Object
- #to_h ⇒ Hash
Methods included from Loggable
Constructor Details
#initialize(args = {}) ⇒ Error
Initialize the error, setting default values
59 60 61 62 63 64 |
# File 'lib/gruf/error.rb', line 59 def initialize(args = {}) args.each do |k, v| send("#{k.to_sym}=", v) if respond_to?(k.to_sym) end @field_errors = [] end |
Instance Attribute Details
#app_code ⇒ Object
Returns the value of attribute app_code.
53 54 55 |
# File 'lib/gruf/error.rb', line 53 def app_code @app_code end |
#code ⇒ Object
Returns the value of attribute code.
53 54 55 |
# File 'lib/gruf/error.rb', line 53 def code @code end |
#debug_info ⇒ Object
Returns the value of attribute debug_info.
53 54 55 |
# File 'lib/gruf/error.rb', line 53 def debug_info @debug_info end |
#field_errors ⇒ Object
Returns the value of attribute field_errors.
53 54 55 |
# File 'lib/gruf/error.rb', line 53 def field_errors @field_errors end |
#grpc_error ⇒ GRPC::BadStatus
138 139 140 |
# File 'lib/gruf/error.rb', line 138 def grpc_error @grpc_error end |
#message ⇒ Object
Returns the value of attribute message.
53 54 55 |
# File 'lib/gruf/error.rb', line 53 def @message end |
#metadata ⇒ Object
Returns the value of attribute metadata.
54 55 56 |
# File 'lib/gruf/error.rb', line 54 def @metadata end |
Instance Method Details
#add_field_error(field_name, error_code, message = '') ⇒ Object
Add a field error to this error package
73 74 75 |
# File 'lib/gruf/error.rb', line 73 def add_field_error(field_name, error_code, = '') @field_errors << Errors::Field.new(field_name, error_code, ) end |
#attach_to_call(active_call) ⇒ Error
106 107 108 109 110 111 112 |
# File 'lib/gruf/error.rb', line 106 def attach_to_call(active_call) [Gruf..to_sym] = serialize if Gruf. if !.empty? && active_call && active_call.respond_to?(:output_metadata) active_call..update() end self end |
#fail!(active_call) ⇒ GRPC::BadStatus
118 119 120 |
# File 'lib/gruf/error.rb', line 118 def fail!(active_call) raise attach_to_call(active_call).grpc_error end |
#serialize ⇒ String
Serialize the error for transport
97 98 99 100 |
# File 'lib/gruf/error.rb', line 97 def serialize serializer = serializer_class.new(self) serializer.serialize.to_s end |
#set_debug_info(detail, stack_trace = []) ⇒ Object
81 82 83 |
# File 'lib/gruf/error.rb', line 81 def set_debug_info(detail, stack_trace = []) @debug_info = Errors::DebugInfo.new(detail, stack_trace) end |
#to_h ⇒ Hash
125 126 127 128 129 130 131 132 133 |
# File 'lib/gruf/error.rb', line 125 def to_h { code: code, app_code: app_code, message: , field_errors: field_errors.map(&:to_h), debug_info: debug_info.to_h } end |