Class: GRPC::GoogleRpcStatusUtils

Inherits:
Object
  • Object
show all
Defined in:
src/ruby/lib/grpc/google_rpc_status_utils.rb

Overview

GoogleRpcStatusUtils provides utilities to convert between a GRPC::Core::Status and a deserialized Google::Rpc::Status proto Returns nil if the grpc-status-details-bin trailer could not be converted to a GoogleRpcStatus due to the server not providing the necessary trailers. Raises an error if the server did provide the necessary trailers but they fail to deseriliaze into a GoogleRpcStatus protobuf.

Class Method Summary collapse

Class Method Details

.extract_google_rpc_status(status) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'src/ruby/lib/grpc/google_rpc_status_utils.rb', line 27

def self.extract_google_rpc_status(status)
  fail ArgumentError, 'bad type' unless status.is_a? Struct::Status
  grpc_status_details_bin_trailer = 'grpc-status-details-bin'
  binstatus = status.[grpc_status_details_bin_trailer]
  return nil if binstatus.nil?

  # Lazily load grpc_c and protobuf_c.so for users of this method.
  require_relative './grpc'
  require 'google/rpc/status_pb'

  Google::Rpc::Status.decode(binstatus)
end