CorvoNfse.Error exception (Corvo NFS-e v0.1.1)

Copy Markdown View Source

The single error type returned by every Corvo NFS-e API call.

Each field mirrors the wire error contract shared by all Corvo SDKs:

  • :status - HTTP status code; 0 for network/timeout failures.
  • :code - stable machine-readable code ("ERROR_VALIDATION", "http_500", "network_error", "timeout", "invalid_json").
  • :message - human-readable message.
  • :details - list of %{"field" => ..., "code" => ..., "message" => ...} maps for body validation failures (passed through unchanged).
  • :request_id - requestId body field or X-Request-Id header.
  • :retry_after - seconds to wait, from retryAfter or Retry-After.

API, network and timeout failures are returned as {:error, %CorvoNfse.Error{}} instead of raised. The struct is nevertheless a proper exception so the one documented raising site - a subsequent page failure inside an iterate stream - can raise it.

Examples

iex> CorvoNfse.Error.message(%CorvoNfse.Error{message: "company not found"})
"company not found"

iex> CorvoNfse.Error.message(%CorvoNfse.Error{status: 404, code: "http_404"})
"Corvo NFS-e API error (status=404, code=\"http_404\")"

Summary

Types

detail()

@type detail() :: %{required(String.t()) => String.t()}

t()

@type t() :: %CorvoNfse.Error{
  __exception__: true,
  code: String.t() | nil,
  details: [detail()] | nil,
  message: String.t() | nil,
  request_id: String.t() | nil,
  retry_after: non_neg_integer() | nil,
  status: non_neg_integer() | nil
}