Solaris.Error exception (Solaris v1.0.0)

Copy Markdown View Source

Structured error type returned by all Solaris API calls.

All public API functions return either {:ok, result} or {:error, %Solaris.Error{}}, never raw exceptions.

Fields

FieldTypeDescription
:codecode/0Normalized atom error code
:messageString.t()Human-readable description
:status`integer()nil`HTTP status code
:details`[map()]nil`Raw error objects from Solaris API
:request_id`String.t()nil`X-Request-Id from the failed request
:change_request_id`String.t()nil`Present when SCA/2FA is required

Error Codes

CodeHTTPDescription
:unauthorized401Invalid or missing credentials
:forbidden403Insufficient permissions
:not_found404Resource does not exist
:conflict409State conflict (e.g. duplicate)
:unprocessable_entity422Validation failure
:rate_limited429Too many requests
:internal_server_error500Solaris server error
:bad_gateway502Upstream error
:service_unavailable503Service temporarily down
:timeoutHTTP timeout
:network_errorTCP/DNS-level failure
:invalid_paramsInvalid arguments to SDK function
:validation_errorLocal validation failure
:unknownUnmapped HTTP status

Summary

Functions

Builds a Solaris.Error from a caught Req/Mint exception.

Builds an :invalid_params error with a custom message.

Builds a :validation_error with a custom message and optional detail list.

Types

code()

@type code() ::
  :unauthorized
  | :forbidden
  | :not_found
  | :conflict
  | :unprocessable_entity
  | :rate_limited
  | :internal_server_error
  | :service_unavailable
  | :bad_gateway
  | :timeout
  | :network_error
  | :invalid_params
  | :validation_error
  | :unknown

t()

@type t() :: %Solaris.Error{
  __exception__: true,
  change_request_id: String.t() | nil,
  code: code(),
  details: [map()] | nil,
  message: String.t(),
  request_id: String.t() | nil,
  status: integer() | nil
}

Functions

from_exception(exception)

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

Builds a Solaris.Error from a caught Req/Mint exception.

from_response(map)

@spec from_response(%{
  :status => integer(),
  :body => term(),
  :headers => term(),
  optional(atom()) => term()
}) :: t()

Builds a Solaris.Error from a Req.Response map.

Extracts the error code, message, details, request ID, and change_request_id from the response status and body.

invalid_params(message)

@spec invalid_params(String.t()) :: t()

Builds an :invalid_params error with a custom message.

validation(message, details \\ [])

@spec validation(String.t(), [map()]) :: t()

Builds a :validation_error with a custom message and optional detail list.