1# Copyright 2017 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15require_relative './grpc' 16require 'google/rpc/status_pb' 17 18# GRPC contains the General RPC module. 19module GRPC 20 # GoogleRpcStatusUtils provides utilities to convert between a 21 # GRPC::Core::Status and a deserialized Google::Rpc::Status proto 22 # Returns nil if the grpc-status-details-bin trailer could not be 23 # converted to a GoogleRpcStatus due to the server not providing 24 # the necessary trailers. 25 # Raises an error if the server did provide the necessary trailers 26 # but they fail to deseriliaze into a GoogleRpcStatus protobuf. 27 class GoogleRpcStatusUtils 28 def self.extract_google_rpc_status(status) 29 fail ArgumentError, 'bad type' unless status.is_a? Struct::Status 30 grpc_status_details_bin_trailer = 'grpc-status-details-bin' 31 return nil if status.metadata[grpc_status_details_bin_trailer].nil? 32 Google::Rpc::Status.decode(status.metadata[grpc_status_details_bin_trailer]) 33 end 34 end 35end 36