Module: GrpcKit::Errors

Included in:
Grpc
Defined in:
lib/grpc_kit/errors.rb

Defined Under Namespace

Classes: Aborted, AlreadyExists, BadStatus, Cancelled, DataLoss, DeadlineExceeded, DoNotUse, FailedPrecondition, Internal, InvalidArgument, NotFound, OutOfRange, PermissionDenied, ResourceExhausted, Unauthenticated, Unavailable, Unimplemented, Unknown

Constant Summary collapse

CODES =
{
  GrpcKit::StatusCodes::CANCELLED => Cancelled,
  GrpcKit::StatusCodes::UNKNOWN => Unknown,
  GrpcKit::StatusCodes::INVALID_ARGUMENT => InvalidArgument,
  GrpcKit::StatusCodes::DEADLINE_EXCEEDED => DeadlineExceeded,
  GrpcKit::StatusCodes::NOT_FOUND => NotFound,
  GrpcKit::StatusCodes::ALREADY_EXISTS => AlreadyExists,
  GrpcKit::StatusCodes::PERMISSION_DENIED => PermissionDenied,
  GrpcKit::StatusCodes::RESOURCE_EXHAUSTED => ResourceExhausted,
  GrpcKit::StatusCodes::FAILED_PRECONDITION => FailedPrecondition,
  GrpcKit::StatusCodes::ABORTED => Aborted,
  GrpcKit::StatusCodes::OUT_OF_RANGE => OutOfRange,
  GrpcKit::StatusCodes::UNIMPLEMENTED => Unimplemented,
  GrpcKit::StatusCodes::INTERNAL => Internal,
  GrpcKit::StatusCodes::UNAVAILABLE => Unavailable,
  GrpcKit::StatusCodes::DATA_LOSS => DataLoss,
  GrpcKit::StatusCodes::UNAUTHENTICATED => Unauthenticated,
  GrpcKit::StatusCodes::DO_NOT_USE => DoNotUse,
}.freeze

Class Method Summary collapse

Class Method Details

.from_status_code(code, message) ⇒ GrpcKit::Errors::BadStatus

Parameters:

  • code (String)

    GrpcKit::StatusCodes’s value

  • message (String)

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/grpc_kit/errors.rb', line 12

def self.from_status_code(code, message)
  if code == GrpcKit::StatusCodes::OK
    raise ArgumentError, 'Status OK is not an error'
  end

  error_class = CODES[code]
  if error_class
    error_class.new(message)
  else
    GrpcKit::Errors::Unknown.new("Received unknown code: code=#{code}\n #{message}")
  end
end