Skip to content

Commit

Permalink
fix: add backwards compatible transition check
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Oct 17, 2024
1 parent 5f9c0f4 commit 610b82c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,35 @@ export class WorkflowContext<TInitialPayload = unknown> {
body?: unknown;
headers?: Record<string, string>;
}
) {
): Promise<CallResponse> {
const { url, method = "GET", body, headers = {} } = callSettings;

const result = await this.addStep(
new LazyCallStep<CallResponse>(stepName, url, method, body, headers ?? {})
new LazyCallStep<CallResponse | string>(stepName, url, method, body, headers ?? {})
);

// <for backwards compatibity>
// if you transition to upstash/workflow from upstash/qstash,
// the out field in the steps will be the body of the response.
// we need to handle them explicitly here
if (typeof result === "string") {
try {
const body = JSON.parse(result);
return {
status: -1,
header: {},
body,
};
} catch {
return {
status: -1,
header: {},
body: result,
};
}
}
// </for backwards compatibity>

try {
return {
...result,
Expand Down

0 comments on commit 610b82c

Please sign in to comment.