HttpOutput
Type, in @jr2/orchestrator/src/effector-wire.ts. It is an export of @jr2/orchestrator, on the Authoring surface page, in Effects.
ts
type HttpOutput = {
outcome: "response";
status: number;
headers: Record<string, string>;
contentType: string;
size: number;
body?: string | undefined;
truncated?: boolean | undefined;
} | {
outcome: "unknown" | "unreachable" | "refused";
reason: string;
};The output of an http Effect: what the onDone of its state gets as event.output. Every outcome is output. A 4xx or 5xx status is output too. Route on outcome:
response: an answer came back.statusis its HTTP status.headers,contentTypeandsizetell about the body.bodyis there when the body is text: at mostmaxBodybytes (truncatedistruewhen jr2 cut it). A body that is not text gives only its size and content type. jr2 replaces each value of an Effect secret that the Effector holds, and its usual encodings, with[secret:<name>], in the body and the headers.unreachable: the call did not go out, for example because the name did not resolve, or the connection or TLS failed.reasontells why.refused: jr2 or the Effector refused the call, and nothing was sent. For example, a path segment that is.,..or empty, or a request that is too large.reasontells why.unknown: the call can have gone out, but no answer came, or jr2 cannot tell after a restart.reasontells why. jr2 does not send it again unless it is markedidempotent.
Forms: it is one of these objects.
Form 1:
outcome,status,headers,contentType,size,body,truncatedoutcome:"response"status:numberheaders:Record<string, string>contentType:stringsize:numberbody(optional):stringtruncated(optional):boolean
Form 2:
outcome,reasonoutcome:"unknown" | "unreachable" | "refused"reason:string
Example
ts
import { fail, http, jr2Setup, type HttpOutput } from "@jr2/orchestrator";
const ok = (output: HttpOutput): boolean => output.outcome === "response" && output.status < 300;
export const machine = jr2Setup({
actors: { health: http({ method: "GET", url: "https://app.example.com/healthz" }), fail: fail() },
}).createMachine({
id: "health",
initial: "checking",
states: {
checking: {
invoke: {
src: "health",
onDone: [
{ guard: ({ event }) => ok(event.output), target: "healthy" },
{ target: "unhealthy" },
],
},
},
healthy: { type: "final" },
// Not a final state: the run ends `failed`, and `jr2 run` exits 1.
unhealthy: { invoke: { src: "fail", input: { reason: "the app is not healthy" } } },
},
});See also