PubsubGrpc.Error (PubsubGrpc v0.4.2)

View Source

Structured error type for PubsubGrpc operations.

All errors returned by the library are wrapped in this struct, providing consistent error handling across authentication, validation, connection, and gRPC API errors.

Fields

  • code - An atom categorizing the error (e.g., :not_found, :validation_error)
  • message - A human-readable error description
  • details - The original error term (e.g., %GRPC.RPCError{}, exception struct)
  • grpc_status - The integer gRPC status code when applicable, nil otherwise

Examples

case PubsubGrpc.create_topic("my-project", "my-topic") do
  {:ok, topic} -> topic
  {:error, %PubsubGrpc.Error{code: :already_exists}} -> "Topic already exists"
  {:error, %PubsubGrpc.Error{code: :unauthenticated}} -> "Auth failed"
  {:error, %PubsubGrpc.Error{} = err} -> "Error: #{err}"
end

Summary

Functions

Creates a new error from a gRPC error.

Creates a new error with the given code and message.

Types

t()

@type t() :: %PubsubGrpc.Error{
  code: atom(),
  details: term(),
  grpc_status: non_neg_integer() | nil,
  message: String.t()
}

Functions

from_grpc_error(error)

@spec from_grpc_error(GRPC.RPCError.t()) :: t()

Creates a new error from a gRPC error.

Maps the gRPC status code to a descriptive atom code and preserves the original error in details.

new(code, message, details \\ nil)

@spec new(atom(), String.t(), term()) :: t()

Creates a new error with the given code and message.