class Status
The grpc-status header represents the gRPC status code.
The grpc-status header contains a numeric status code (0-16) indicating the result of the RPC call.
Status code 0 indicates success (OK), while other codes indicate various error conditions.
This header can appear both as an initial header (for trailers-only responses) and as a trailer.
Definitions
def self.parse(value)
Parse a status code from a header value.
Signature
-
parameter
valueString The header value to parse.
-
returns
Status A new Status instance.
Implementation
def self.parse(value)
new(value.to_i)
end
def initialize(value)
Initialize the status header with the given value.
Signature
-
parameter
valueString | Integer The status code as a string or integer.
Implementation
def initialize(value)
@value = value.to_i
end
def to_i
Get the status code as an integer.
Signature
-
returns
Integer The status code.
Implementation
def to_i
@value
end
def to_s
Serialize the status code to a string.
Signature
-
returns
String The status code as a string.
Implementation
def to_s
@value.to_s
end
def ==(other)
Check equality with another status or integer value.
Signature
-
parameter
otherStatus | Integer The value to compare with.
-
returns
Boolean if the status codes are equal.
Implementation
def ==(other)
@value == other.to_i
end
def hash
Generate hash for use in Hash/Set collections.
Signature
-
returns
Integer The hash value based on the status code.
Implementation
def hash
@value.hash
end
def ok?
Check if this status represents success (status code 0).
Signature
-
returns
Boolean trueif the status code is 0 (OK).
Implementation
def ok?
@value == 0
end
def <<(value)
Merge another status value (takes the new value, as status should only appear once)
Signature
-
parameter
valueString | Integer The new status code
Implementation
def <<(value)
@value = value.to_i
return self
end
def self.trailer?
Whether this header is acceptable in HTTP trailers.
The grpc-status header can appear in trailers as per the gRPC specification.
Signature
-
returns
Boolean true, as grpc-status can appear in trailers.
Implementation
def self.trailer?
true
end