Skip to content

Commit

Permalink
fix: add failHeader parameter to failureFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Aug 20, 2024
1 parent 751b45b commit 6f45c85
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/client/workflow/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,11 @@ describe.skip("live serve tests", () => {
throw new Error("my-custom-error");
});
},
failureFunction: async (context, failStatus, failResponse) => {
failureFunction: async (context, failStatus, failResponse, failHeaders) => {
expect(failStatus).toBe(500);
expect(failResponse).toBe("my-custom-error");
expect(context.headers.get("authentication")).toBe("Bearer secretPassword");
expect(failHeaders["Content-Length"][0]).toBe("45");
finishState.finish();
return;
},
Expand Down
3 changes: 2 additions & 1 deletion src/client/workflow/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export type WorkflowServeOptions<
failureFunction?: (
context: Omit<WorkflowContext, "run" | "sleepUntil" | "sleep" | "call">,
failStatus: number,
failResponse: string
failResponse: string,
failHeader: Record<string, string[]>
) => Promise<void>;
/**
* Base Url of the workflow endpoint
Expand Down
4 changes: 2 additions & 2 deletions src/client/workflow/workflow-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const handleFailure = async <TInitialPayload>(
}

try {
const { status, sourceHeader, body, workflowRunId, url, sourceBody } = JSON.parse(
const { status, header, body, url, sourceHeader, sourceBody, workflowRunId } = JSON.parse(
requestPayload
) as {
status: number;
Expand Down Expand Up @@ -303,7 +303,7 @@ export const handleFailure = async <TInitialPayload>(
debug,
});

await failureFunction(workflowContext, status, errorPayload.message);
await failureFunction(workflowContext, status, errorPayload.message, header);
} catch (error) {
return err(error as Error);
}
Expand Down

0 comments on commit 6f45c85

Please sign in to comment.