class StatelyDB::Error
The Error class contains common StatelyDB error types.
def self.from(error)
-
(StatelyDB::Error)
-
Parameters:
-
error
(Exception
) --
def self.from(error) return error if error.is_a?(StatelyDB::Error) if error.is_a?(GRPC::BadStatus) status = error.to_rpc_status unless status.nil? || status.details.empty? raw_detail = status.details[0] if raw_detail.type_url == "type.googleapis.com/stately.errors.StatelyErrorDetails" error_details = Stately::Errors::StatelyErrorDetails.decode(raw_detail.value) upstream_cause = error_details.upstream_cause.empty? ? nil : StandardError.new(error_details.upstream_cause) # rubocop:disable Metrics/BlockNesting return new(error_details.message, code: error.code, stately_code: error_details.stately_code, cause: upstream_cause) end end end new(error.message, code: GRPC::Core::StatusCodes::UNKNOWN, stately_code: "Unknown", cause: error) end
def self.grpc_code_to_string(code)
-
(String)
-
Parameters:
-
code
(Integer
) --
def self.grpc_code_to_string(code) if code > 0 GRPC::Core::StatusCodes.constants.find do |c| GRPC::Core::StatusCodes.const_get(c) === code end.to_s.split("_").collect(&:capitalize).join else "Unknown" end end
def code_string
-
(String)
-
def code_string self.class.grpc_code_to_string(@code) end
def initialize(message, code: nil, stately_code: nil, cause: nil)
-
cause
(Exception
) -- -
stately_code
(String
) -- -
code
(Integer
) -- -
message
(String
) --
def initialize(message, code: nil, stately_code: nil, cause: nil) code_str = self.class.grpc_code_to_string(code) super("(#{code_str}/#{stately_code}): #{message}") @code = code @stately_code = stately_code @cause = cause end