Every way a Glean call can fail, in one struct.
Operations return {:ok, result} or {:error, %Gleanex.Error{}} and never
both. Match on :reason to tell failures apart:
:config- bad or missing settings, raised or returned before any request is sent. Missing token, unresolvable domain, wrong token scope.:transport- the request never got a response: timeout, refused connection, TLS failure.exceptionholds the underlying error.:rate_limited- HTTP 429.retry_afterholds the header value in seconds when Glean sent one.:problem_detail- the response carried an RFC 7807 body, parsed intoproblem.:http- any other unsuccessful status, with the decodedbody.
Examples
case Gleanex.Client.Search.search(body, config: config) do
{:ok, results} -> results
{:error, %Gleanex.Error{reason: :rate_limited, retry_after: seconds}} -> back_off(seconds)
{:error, %Gleanex.Error{reason: :problem_detail, problem: problem}} -> Logger.error(problem.detail)
{:error, error} -> raise error
end
Summary
Functions
A configuration failure. Raised by Gleanex.new/1, returned by scope checks.
Wrap a transport level exception.
Wrap an unsuccessful response.
Types
@type reason() :: :config | :transport | :rate_limited | :problem_detail | :http
@type t() :: %Gleanex.Error{ __exception__: term(), body: term(), exception: Exception.t() | nil, message: String.t(), operation: {module(), atom()} | nil, problem: Gleanex.ProblemDetail.t() | nil, reason: reason(), retry_after: integer() | nil, status: integer() | nil }
Functions
A configuration failure. Raised by Gleanex.new/1, returned by scope checks.
@spec from_exception(Exception.t(), {module(), atom()} | nil) :: t()
Wrap a transport level exception.
@spec from_response(Req.Response.t(), {module(), atom()} | nil) :: t()
Wrap an unsuccessful response.
operation is the {module, function} pair the generated code reports, used
only to make the message readable.