Exception: Protocol::GRPC::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Protocol::GRPC::Error
- Defined in:
- lib/protocol/grpc/error.rb
Overview
Base exception class for gRPC errors
Direct Known Subclasses
Cancelled, DeadlineExceeded, Internal, InvalidArgument, NotFound, Unauthenticated, Unavailable
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
-
.error_class_for_status(status_code) ⇒ Object
Map status code to error class.
-
.for(status_code, message = nil, metadata: {}) ⇒ Object
Create an appropriate error instance for the given status code.
Instance Method Summary collapse
-
#initialize(status_code, message = nil, details: nil, metadata: {}) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(status_code, message = nil, details: nil, metadata: {}) ⇒ Error
Returns a new instance of Error.
16 17 18 19 20 21 |
# File 'lib/protocol/grpc/error.rb', line 16 def initialize(status_code, = nil, details: nil, metadata: {}) @status_code = status_code @details = details @metadata = super( || Status::DESCRIPTIONS[status_code]) end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
10 11 12 |
# File 'lib/protocol/grpc/error.rb', line 10 def details @details end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/protocol/grpc/error.rb', line 10 def @metadata end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
10 11 12 |
# File 'lib/protocol/grpc/error.rb', line 10 def status_code @status_code end |
Class Method Details
.error_class_for_status(status_code) ⇒ Object
Map status code to error class
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/protocol/grpc/error.rb', line 26 def self.error_class_for_status(status_code) case status_code when Status::CANCELLED then Cancelled when Status::INVALID_ARGUMENT then InvalidArgument when Status::DEADLINE_EXCEEDED then DeadlineExceeded when Status::NOT_FOUND then NotFound when Status::INTERNAL then Internal when Status::UNAVAILABLE then Unavailable when Status::UNAUTHENTICATED then Unauthenticated else Error end end |
.for(status_code, message = nil, metadata: {}) ⇒ Object
Create an appropriate error instance for the given status code
45 46 47 48 49 50 51 52 53 |
# File 'lib/protocol/grpc/error.rb', line 45 def self.for(status_code, = nil, metadata: {}) error_class = error_class_for_status(status_code) if error_class == Error error_class.new(status_code, , metadata: ) else error_class.new(, metadata: ) end end |