From 610b82cc149c578c865b312c20e9895cad2d750c Mon Sep 17 00:00:00 2001 From: CahidArda Date: Thu, 17 Oct 2024 14:33:50 +0300 Subject: [PATCH] fix: add backwards compatible transition check --- src/context/context.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/context/context.ts b/src/context/context.ts index eb7f53c..5bf69bc 100644 --- a/src/context/context.ts +++ b/src/context/context.ts @@ -286,13 +286,35 @@ export class WorkflowContext { body?: unknown; headers?: Record; } - ) { + ): Promise { const { url, method = "GET", body, headers = {} } = callSettings; const result = await this.addStep( - new LazyCallStep(stepName, url, method, body, headers ?? {}) + new LazyCallStep(stepName, url, method, body, headers ?? {}) ); + // + // 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, + }; + } + } + // + try { return { ...result,