Interface FailureWithReason

A failure explained by a reason: the last attempt reported a failure, or a hook returned FailWorkflow.

import assert from "node:assert/strict";
import { LocalExecutor } from "itinera/executor";
import { Step } from "itinera/step";
import { Workflow } from "itinera/workflow";

class Charge extends Step {
override run(): never {
throw new Error("gateway down");
}
}

class Orders extends Workflow {}

export default (async () => {
const orders = Orders.builder()
.name("orders")
.step(Charge.builder("charge"))
.build();
const instance = orders.instance(new Map([["order", "A-1"]]));

const result = await new LocalExecutor().run(instance);

assert.equal(result.journeyId, instance.journeyId);
assert.ok(result.isFailed());
assert.deepEqual(result.status.dataBag.keys(), ["order"]);
assert.equal(result.failure?.cause, "abnormal termination");
assert.equal(result.failure.errorMessage, "gateway down");
assert.equal(result.abort, undefined);
})();
interface FailureWithReason {
    cause: "failure" | "FailWorkflow" | "retries exhausted";
    error?: undefined;
    errorMessage?: undefined;
    reason: Reason;
}

Index

cause: "failure" | "FailWorkflow" | "retries exhausted"

Why the journey failed.

error?: undefined

Never present: a reason explains this failure, not an error.

errorMessage?: undefined

Never present: a reason explains this failure, not an error.

reason: Reason

The reason the step or the hook gave.