class GRPC::BadStatus
BadStatus
is an exception class that indicates that an error occurred at either end of a GRPC
connection. When raised, it indicates that a status error should be returned to the other end of a GRPC
connection; when caught it means that this end received a status error.
There is also subclass of BadStatus
in this module for each GRPC
status. E.g., the GRPC::Cancelled
class corresponds to status CANCELLED.
See github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/status.h for detailed descriptions of each status code.
Attributes
Public Class Methods
Source
# File src/ruby/lib/grpc/errors.rb, line 40 def initialize(code, details = 'unknown cause', metadata = {}, debug_error_string = nil) exception_message = "#{code}:#{details}" if debug_error_string exception_message += ". debug_error_string:{#{debug_error_string}}" end super(exception_message) @code = code @details = details @metadata = metadata @debug_error_string = debug_error_string end
@param code [Numeric] the status code @param details [String] the details of the exception @param metadata [Hash] the error’s metadata
Source
# File src/ruby/lib/grpc/errors.rb, line 77 def self.new_status_exception(code, details = 'unknown cause', metadata = {}, debug_error_string = nil) codes = {} codes[OK] = Ok codes[CANCELLED] = Cancelled codes[UNKNOWN] = Unknown codes[INVALID_ARGUMENT] = InvalidArgument codes[DEADLINE_EXCEEDED] = DeadlineExceeded codes[NOT_FOUND] = NotFound codes[ALREADY_EXISTS] = AlreadyExists codes[PERMISSION_DENIED] = PermissionDenied codes[UNAUTHENTICATED] = Unauthenticated codes[RESOURCE_EXHAUSTED] = ResourceExhausted codes[FAILED_PRECONDITION] = FailedPrecondition codes[ABORTED] = Aborted codes[OUT_OF_RANGE] = OutOfRange codes[UNIMPLEMENTED] = Unimplemented codes[INTERNAL] = Internal codes[UNAVAILABLE] = Unavailable codes[DATA_LOSS] = DataLoss if codes[code].nil? BadStatus.new(code, details, metadata, debug_error_string) else codes[code].new(details, metadata, debug_error_string) end end
Public Instance Methods
Source
# File src/ruby/lib/grpc/errors.rb, line 69 def to_rpc_status GoogleRpcStatusUtils.extract_google_rpc_status(to_status) rescue Google::Protobuf::ParseError => parse_error GRPC.logger.warn('parse error: to_rpc_status failed') GRPC.logger.warn(parse_error) nil end
Converts the exception to a deserialized {Google::Rpc::Status} object. Returns ‘nil` if the `grpc-status-details-bin` trailer could not be converted to a {Google::Rpc::Status} due to the server not providing the necessary trailers.
@return [Google::Rpc::Status, nil]
Source
# File src/ruby/lib/grpc/errors.rb, line 59 def to_status Struct::Status.new(code, details, metadata, debug_error_string) end
Converts the exception to a {Struct::Status} for use in the networking wrapper layer.
@return [Struct::Status] with the same code and details