GcpGcs.Error (GcpGcs v0.2.0)

Copy Markdown View Source

Structured error type for GcpGcs operations.

Every error returned by the library is wrapped in this struct, giving consistent handling across authentication, validation, transport, and Google Cloud Storage API errors.

Fields

  • code — an atom categorizing the error (e.g. :not_found, :validation_error)
  • message — a human-readable description
  • details — the original error term (decoded JSON body, exception, etc.)
  • status — the integer HTTP status code when applicable, nil otherwise

Examples

case GcpGcs.get_object("my-bucket", "missing.txt") do
  {:ok, object} -> object
  {:error, %GcpGcs.Error{code: :not_found}} -> "no such object"
  {:error, %GcpGcs.Error{code: :unauthenticated}} -> "auth failed"
  {:error, %GcpGcs.Error{} = err} -> "Error: #{err}"
end

Summary

Functions

Builds an error from an HTTP response.

Maps a transport-level reason (Finch/Mint error) to an error struct.

Creates a new error with the given code and message.

Types

t()

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

Functions

from_response(status, body)

@spec from_response(non_neg_integer(), term()) :: t()

Builds an error from an HTTP response.

Maps the status code to a descriptive atom and extracts the message from a decoded GCS JSON error body (%{"error" => %{"message" => ...}}) when present.

from_transport(exception)

@spec from_transport(term()) :: t()

Maps a transport-level reason (Finch/Mint error) to an error struct.

new(code, message, details \\ nil)

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

Creates a new error with the given code and message.