Skip to main content
TrueMath distinguishes two kinds of failure: transport errors (the request itself was malformed or unauthorized) and calculation errors (the request was valid but the calculation could not complete).

Transport errors

Transport errors use a standard HTTP status code and a JSON body of the form:

Calculation errors

A calculation that cannot complete returns an HTTP 200 with status: "error" in the body and an errors array — one entry per problem. Each entry has:
  • code — a stable, machine-readable identifier for the failure. Branch on this, not on message. The full set is listed below.
  • message — an English description template containing numbered %argN% placeholders. It is not pre-filled; substitute the args before displaying it (see Building the message).
  • args — a positional array of string values for the %argN% placeholders in message (%arg0%args[0], %arg1%args[1], and so on). Read them directly when you need the raw values, such as the unit names. See Building the message.
  • offset — present only on input.syntax_error: an integer, the zero-based character offset of the error within the equation. It is a caret position between characters — 0 is before the first character, 1 is after the first, 2 after the second, and so on.
  • missing — when the calculation is blocked on inputs, the variables you could supply to continue, grouped as alternatives. See Missing inputs.
args, offset, and missing are each conditionally included — present only when the error uses them, and omitted (never null) otherwise. A consumer must not assume the keys exist. An incompatible-units error, for example, carries the offending units in args, to substitute into the message template:

Building the message

message is a template, not a finished string. Each placeholder is a numbered token %argN% (zero-indexed), filled from args by index%arg0% is replaced with args[0], %arg1% with args[1], and so on (the reference client matches /%arg(\d+)%/g):
Substitution rules:
  • If args is absent or empty, render message as-is — it has no placeholders to fill.
  • Replace each %argN% with args[N]. The values are already strings in the response.
  • Match by index, not order of appearance: %arg1% always means args[1], even if it appears before %arg0% in the text.
  • If a placeholder’s index has no matching value (N is at or beyond the length of args), leave the literal %argN% token in place — do not blank it.
If you only need the offending values — to highlight a field, say — read them straight from args and ignore message. The same substitution applies to every error, engine- or request-originated.

Missing inputs

When an error is blocked on inputs, missing lists the variables you could supply to continue. It is an array of option groups — each inner array is one set of variables that must be supplied together to unblock the calculation. More than one group means there are alternative ways to proceed. Read missing as: provide every variable in any one group, then retry. Each entry is a fully formed variable object — id, key, title, description, and a display render snapshot (the same display shape as a calculation result) — but with no value, since these are candidates you can supply, not resolved values.
The example has one group with one variable, but a group may list several variables that must be provided together, and there may be several groups. For instance, one group might ask for both down_payment and loan_term while another asks only for loan_amount — satisfying either group (all of its variables) lets the calculation continue.

Calculation error codes

Codes are namespaced by category — input.* for a malformed or under-specified request, calculation.* for a valid request the system cannot solve, and math.* for an undefined numeric result. Branch on the exact code. Input errors — the request is malformed or under-specified:
input.missing_calculate_target and input.unknown_calculate_target are distinct codes: the first means no target was named in the request; the second means the named target is not a variable in this domain.
Calculation errors — the inputs are valid but the system cannot solve for the target: Math errors — a numeric result is undefined or unrepresentable: