Interface Reason

Why a step failed or was skipped, or why a hook failed the journey: a code, and optionally a message and details, as events and the result carry it.

The details are a value, captured when the reason was given, so changing what was given afterwards changes nothing here.

import assert from "node:assert/strict";
import type { Reason } from "itinera/step";

function explain(reason: Reason): string {
return reason.message === undefined
? reason.code
: `${reason.code}: ${reason.message}`;
}

assert.equal(explain({ code: "declined" }), "declined");
assert.equal(
explain({
code: "declined",
message: "card expired",
details: { last4: "4242" },
}),
"declined: card expired",
);
interface Reason {
    code: string;
    details?: PlainValue;
    message?: string;
}

Index

code: string

A short code a program can compare, such as "declined".

details?: PlainValue

Anything else the reason says, as a value.

message?: string

A message for people.