Exception: Protocol::GRPC::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/protocol/grpc/error.rb

Overview

Base exception class for gRPC errors

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, message = nil, details: nil, metadata: {})
	@status_code = status_code
	@details = details
	@metadata = 
	super(message || Status::DESCRIPTIONS[status_code])
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



10
11
12
# File 'lib/protocol/grpc/error.rb', line 10

def details
  @details
end

#metadataObject (readonly)

Returns the value of attribute metadata.



10
11
12
# File 'lib/protocol/grpc/error.rb', line 10

def 
  @metadata
end

#status_codeObject (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, message = nil, metadata: {})
	error_class = error_class_for_status(status_code)
	
	if error_class == Error
		error_class.new(status_code, message, metadata: )
	else
		error_class.new(message, metadata: )
	end
end