Skip to content

Commit f1aa724

Browse files
committed
fix: failure function headers with context.call
1 parent d4248b2 commit f1aa724

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

examples/ci/app/ci/constants.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,13 @@ export const TEST_ROUTES: Pick<TestConfig, "route" | "waitForSeconds">[] = [
6767
{
6868
route: "wait-for-event/workflow",
6969
waitForSeconds: 20
70-
}
70+
},
71+
{
72+
route: "call/workflow-with-failureFunction",
73+
waitForSeconds: 5
74+
},
75+
{
76+
route: "call/workflow-with-failureUrl",
77+
waitForSeconds: 5
78+
},
7179
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { serve } from "@upstash/workflow/nextjs";
2+
import { BASE_URL, TEST_ROUTE_PREFIX } from "app/ci/constants";
3+
import { testServe, expect } from "app/ci/utils";
4+
import { saveResult } from "app/ci/upstash/redis"
5+
import { FAILING_HEADER, FAILING_HEADER_VALUE } from "../constants";
6+
7+
const testHeader = `test-header-foo`
8+
const headerValue = `header-foo`
9+
const payload = "my-payload"
10+
11+
const thirdPartyEndpoint = `${TEST_ROUTE_PREFIX}/call/third-party`
12+
13+
export const { POST, GET } = testServe(
14+
serve<string>(
15+
async (context) => {
16+
17+
const { body: patchResult, status, header } = await context.call("get call", {
18+
url: thirdPartyEndpoint,
19+
method: "PATCH",
20+
retries: 0
21+
});
22+
23+
expect(status, 401)
24+
expect(patchResult as string, "failing request");
25+
expect(header[FAILING_HEADER][0], FAILING_HEADER_VALUE)
26+
27+
await saveResult(
28+
context,
29+
patchResult as string,
30+
)
31+
}, {
32+
baseUrl: BASE_URL,
33+
retries: 0,
34+
failureFunction() {
35+
console.log("SHOULDNT RUN");
36+
},
37+
}
38+
), {
39+
expectedCallCount: 4,
40+
expectedResult: "failing request",
41+
payload,
42+
headers: {
43+
[ testHeader ]: headerValue,
44+
}
45+
}
46+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { serve } from "@upstash/workflow/nextjs";
2+
import { BASE_URL, TEST_ROUTE_PREFIX } from "app/ci/constants";
3+
import { testServe, expect } from "app/ci/utils";
4+
import { saveResult } from "app/ci/upstash/redis"
5+
import { FAILING_HEADER, FAILING_HEADER_VALUE } from "../constants";
6+
7+
const testHeader = `test-header-foo`
8+
const headerValue = `header-foo`
9+
const payload = "my-payload"
10+
11+
const thirdPartyEndpoint = `${TEST_ROUTE_PREFIX}/call/third-party`
12+
13+
export const { POST, GET } = testServe(
14+
serve<string>(
15+
async (context) => {
16+
17+
const { body: patchResult, status, header } = await context.call("get call", {
18+
url: thirdPartyEndpoint,
19+
method: "PATCH",
20+
retries: 0
21+
});
22+
23+
expect(status, 401)
24+
expect(patchResult as string, "failing request");
25+
expect(header[FAILING_HEADER][0], FAILING_HEADER_VALUE)
26+
27+
await saveResult(
28+
context,
29+
patchResult as string,
30+
)
31+
}, {
32+
baseUrl: BASE_URL,
33+
retries: 0,
34+
failureUrl: thirdPartyEndpoint
35+
// failureUrl: `${TEST_ROUTE_PREFIX}/call/workflow-with-failureUrl`
36+
}
37+
), {
38+
expectedCallCount: 4,
39+
expectedResult: "failing request",
40+
payload,
41+
headers: {
42+
[ testHeader ]: headerValue,
43+
}
44+
}
45+
)

src/workflow-requests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ export const getHeaders = (
299299
}
300300

301301
if (failureUrl) {
302+
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
302303
if (!step?.callUrl) {
303-
baseHeaders[`Upstash-Failure-Callback-Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
304+
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
304305
}
305-
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
306306
}
307307

308308
// if retries is set or if call url is passed, set a retry

0 commit comments

Comments
 (0)