GcpCompute.Error exception (GcpCompute v0.2.0)

Copy Markdown View Source

Normalized error returned by every GcpCompute function.

Errors are returned as {:error, %GcpCompute.Error{}}. The struct is also an exception, so it can be raised by the bang variants (insert_instance!/3, …) or with raise/1.

Fields

  • :reason — a coarse, matchable atom (:api_error, :transport, :timeout, :token_fetch_failed, :operation_failed, …).
  • :status — HTTP status code, when the error came from an API response.
  • :message — human readable message (from GCP when available).
  • :errors — the raw error.errors list returned by the Compute API.
  • :body — the underlying body/exception, for debugging.
  • :operation — the failed GcpCompute.Operation, for operation errors.

Summary

Functions

Build a transport-level error from a Req/Mint exception.

Build an error from a non-2xx Compute API response.

Types

t()

@type t() :: %GcpCompute.Error{
  __exception__: true,
  body: term(),
  errors: list() | nil,
  message: String.t() | nil,
  operation: GcpCompute.Operation.t() | nil,
  reason: atom(),
  status: non_neg_integer() | nil
}

Functions

from_exception(exception)

@spec from_exception(Exception.t()) :: t()

Build a transport-level error from a Req/Mint exception.

from_response(status, body)

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

Build an error from a non-2xx Compute API response.

Handles the standard Google error envelope:

%{"error" => %{"code" => 403, "message" => "...", "errors" => [...]}}