SudregEx.Error exception (sudreg_ex v0.1.0)

Copy Markdown View Source

A failed Sudski registar API interaction.

When the response carries the API's JSON error envelope the error_code, error_message and log_id fields are populated (always quote log_id when contacting upstream support). http_status is set whenever there was a response; reason carries a transport/decoding failure when there was not.

Summary

Functions

Builds an error from a response status and body.

Types

t()

@type t() :: %SudregEx.Error{
  __exception__: true,
  error_code: integer() | String.t() | nil,
  error_message: String.t() | nil,
  http_status: pos_integer() | nil,
  log_id: integer() | String.t() | nil,
  reason: term()
}

Functions

from_response(status, body)

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

Builds an error from a response status and body.

A map body, or a binary that parses as a JSON object, is read as an error envelope: both the Sudreg shape (error_code/error_message/log_id, on 400/500) and the ORDS problem+json shape (code/message, on 401) are recognised. Any other body (e.g. the ORDS HTML page) yields an error carrying just the status.