View Source QRNBU.Error exception (NBU payment QR v0.3.3)
Structured error types for NBU QR code library.
This module provides consistent error handling with categorized error types, field information, and error codes for programmatic handling.
Error Categories
:validation_error- Data validation failures:encoding_error- Character encoding failures:format_error- Output formatting failures:unsupported_error- Unsupported feature/version requests
Examples
iex> error = QRNBU.Error.validation_error(:iban, "Invalid checksum")
iex> raise error
** (QRNBU.Error) Validation error on field 'iban': Invalid checksum
iex> QRNBU.Error.encoding_error("Failed to encode to CP1251")
%QRNBU.Error{code: :encoding_error, message: "Encoding error: Failed to encode to CP1251", field: nil, details: %{}}
Summary
Functions
Creates an encoding error.
Creates a formatting error.
Wraps multiple error messages into a formatted string.
Converts error to a simple string message.
Creates an unsupported feature/version error.
Creates a validation error for a specific field.
Types
@type error_code() ::
:validation_error | :encoding_error | :format_error | :unsupported_error
@type t() :: %QRNBU.Error{ __exception__: true, code: error_code(), details: map() | nil, field: atom() | nil, message: String.t() }
Functions
Creates an encoding error.
Examples
iex> QRNBU.Error.encoding_error("CP1251 encoding failed")
%QRNBU.Error{
code: :encoding_error,
message: "Encoding error: CP1251 encoding failed",
field: nil,
details: %{}
}
Creates a formatting error.
Examples
iex> QRNBU.Error.format_error("Invalid line ending for V003")
%QRNBU.Error{
code: :format_error,
message: "Format error: Invalid line ending for V003",
field: nil,
details: %{}
}
Wraps multiple error messages into a formatted string.
Converts error to a simple string message.
Creates an unsupported feature/version error.
Examples
iex> QRNBU.Error.unsupported_error("Version 4 is not supported")
%QRNBU.Error{
code: :unsupported_error,
message: "Unsupported: Version 4 is not supported",
field: nil,
details: %{}
}
Creates a validation error for a specific field.
Examples
iex> QRNBU.Error.validation_error(:iban, "Must be 29 characters")
%QRNBU.Error{
code: :validation_error,
field: :iban,
message: "Validation error on field 'iban': Must be 29 characters",
details: %{}
}