The normalised error codes, and the function that derives them from the gateway's messages.
The gateway answers a refusal with a message that is sometimes a code
("INSUFFICIENT_BUNDLE") and sometimes a sentence ("Invalid From Sender ID").
normalize/1 turns both into one code, so %Unicom360.Error{code: code} compares the same way
whichever form the gateway used:
iex> Unicom360.Codes.normalize("Invalid From Sender ID")
"INVALID_SENDER_ID"
iex> Unicom360.Codes.normalize("DUPLICATE_MSG_REF")
"DUPLICATE_REFERENCE"
iex> Unicom360.Codes.normalize("INSUFFICIENT_BUNDLE: no international SMS bundle")
"INSUFFICIENT_BUNDLE"
iex> Unicom360.Codes.normalize("SOME_FUTURE_CODE")
"SOME_FUTURE_CODE"
iex> Unicom360.Codes.normalize("Missing required keys: [\"message\"]")
"UNKNOWN"Codes are plain strings, so a code this version does not know passes through unchanged. Each
known code also has a function returning it (Unicom360.Codes.insufficient_bundle/0 returns
"INSUFFICIENT_BUNDLE"), and known/0 lists them all. In a pattern, match the string itself:
case Unicom360.SMS.send(client, params) do
{:ok, result} -> result
{:error, %Unicom360.Error{code: "INSUFFICIENT_BUNDLE"}} -> top_up()
end
Summary
Functions
Returns "AUTHENTICATION_FAILED".
Returns "CLIENT_DISABLED".
Returns "CLIENT_NOT_FOUND".
Returns "CREDENTIAL_DISABLED".
Returns "CREDENTIAL_EXPIRED".
Returns "DUPLICATE_REFERENCE".
Returns "INSUFFICIENT_BUNDLE".
Returns "INVALID_AUTHORIZATION".
Returns "INVALID_NUMBER".
Returns "INVALID_PARAMETERS".
Returns "INVALID_RECIPIENT_LIMIT".
Returns "INVALID_SENDER_ID".
Returns "INVALID_USER_REFERENCE_ID".
Returns "IP_NOT_ALLOWED".
Every code this version documents, as strings.
Returns "LANGUAGE_REQUIRED".
Returns "MEDIA_URL_INVALID".
Returns "MISSING_API_KEY".
Returns "NO_VALID_RECIPIENTS".
Normalises a gateway message to an error code.
Returns "RATE_LIMIT_EXCEEDED".
Returns "REACTION_TARGET_NOT_FOUND".
Returns "REPLY_TO_NOT_FOUND".
Returns "SEND_FAILED".
Returns "SENDER_ID_NOT_ALLOWED".
Returns "SENDER_REQUIRED".
Returns "SESSION_WINDOW_CLOSED".
Returns "TEMPLATE_NOT_APPROVED".
Returns "TEMPLATE_NOT_FOUND".
Returns "TEMPLATE_SENDER_MISMATCH".
Returns "UNKNOWN".
Functions
@spec authentication_failed() :: String.t()
Returns "AUTHENTICATION_FAILED".
@spec client_disabled() :: String.t()
Returns "CLIENT_DISABLED".
@spec client_not_found() :: String.t()
Returns "CLIENT_NOT_FOUND".
@spec credential_disabled() :: String.t()
Returns "CREDENTIAL_DISABLED".
@spec credential_expired() :: String.t()
Returns "CREDENTIAL_EXPIRED".
@spec duplicate_reference() :: String.t()
Returns "DUPLICATE_REFERENCE".
@spec insufficient_bundle() :: String.t()
Returns "INSUFFICIENT_BUNDLE".
@spec invalid_authorization() :: String.t()
Returns "INVALID_AUTHORIZATION".
@spec invalid_number() :: String.t()
Returns "INVALID_NUMBER".
@spec invalid_parameters() :: String.t()
Returns "INVALID_PARAMETERS".
@spec invalid_recipient_limit() :: String.t()
Returns "INVALID_RECIPIENT_LIMIT".
@spec invalid_sender_id() :: String.t()
Returns "INVALID_SENDER_ID".
@spec invalid_user_reference_id() :: String.t()
Returns "INVALID_USER_REFERENCE_ID".
@spec ip_not_allowed() :: String.t()
Returns "IP_NOT_ALLOWED".
@spec known() :: [String.t()]
Every code this version documents, as strings.
@spec language_required() :: String.t()
Returns "LANGUAGE_REQUIRED".
@spec media_url_invalid() :: String.t()
Returns "MEDIA_URL_INVALID".
@spec missing_api_key() :: String.t()
Returns "MISSING_API_KEY".
@spec no_valid_recipients() :: String.t()
Returns "NO_VALID_RECIPIENTS".
Normalises a gateway message to an error code.
The first matching rule wins: an exact match in the alias table; a message that is itself a
code (^[A-Z][A-Z0-9_]*$, aliased when the table has it); a message that starts with a code
followed by a colon and white space (the code, aliased when the table has it); otherwise
"UNKNOWN". Matching is exact and case-sensitive. Anything that is not a string is
"UNKNOWN".
@spec rate_limit_exceeded() :: String.t()
Returns "RATE_LIMIT_EXCEEDED".
@spec reaction_target_not_found() :: String.t()
Returns "REACTION_TARGET_NOT_FOUND".
@spec reply_to_not_found() :: String.t()
Returns "REPLY_TO_NOT_FOUND".
@spec send_failed() :: String.t()
Returns "SEND_FAILED".
@spec sender_id_not_allowed() :: String.t()
Returns "SENDER_ID_NOT_ALLOWED".
@spec sender_required() :: String.t()
Returns "SENDER_REQUIRED".
@spec session_window_closed() :: String.t()
Returns "SESSION_WINDOW_CLOSED".
@spec template_not_approved() :: String.t()
Returns "TEMPLATE_NOT_APPROVED".
@spec template_not_found() :: String.t()
Returns "TEMPLATE_NOT_FOUND".
@spec template_sender_mismatch() :: String.t()
Returns "TEMPLATE_SENDER_MISMATCH".
@spec unknown() :: String.t()
Returns "UNKNOWN".