Method: Gruf::Client::ErrorFactory#from_exception

Defined in:
lib/gruf/client/error_factory.rb

#from_exception(exception) ⇒ Gruf::Client::Errors::Base|SignalException

Determine the proper error class to raise given the incoming exception. This will attempt to coalesce the exception object into the appropriate Gruf::Client::Errors subclass, or fallback to the default class if none is found (or it is a StandardError or higher-level error). It will leave alone Signals instead of attempting to coalesce them.

Parameters:

  • exception (Exception)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gruf/client/error_factory.rb', line 48

def from_exception(exception)
  # passthrough on Signals, we don't want to mess with these
  return exception if exception.is_a?(SignalException)

  exception_class = determine_class(exception)
  if exception.is_a?(GRPC::BadStatus)
    # if it's a GRPC::BadStatus code, let's check for any trailing error metadata and decode it
    exception_class.new(deserialize(exception))
  else
    # otherwise, let's just capture the error and build the wrapper class
    exception_class.new(exception)
  end
end