Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 11, 2024
1 parent 3b23574 commit cced343
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/handlers/callbacks-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,42 @@ export function proxyWorkflowCallbacks(context: Context): ProxyCallbacks {
context.logger.info(`No callbacks found for event ${prop}`);
return { status: 204, reason: "skipped" };
}
return (async () => {

// somehow proxies affect error handling
async function run() {
try {
await Promise.all(target[prop].map((callback) => handleCallback(callback, context)));
return await Promise.all(target[prop].map((callback) => handleCallback(callback, context)));
} catch (er) {
return er;
}
}

function trier() {
try {
// we are invoking the function here so, wrap this anon fn in a try block
(async () => {
const obj = await run() as Record<string, unknown>;
let error: { code: number, seconds: number, errorMessage: string } | undefined;

if ("er" in obj) {
error = obj.er as { code: number, seconds: number, errorMessage: string };
}

if (error && error.code === 420 || error?.errorMessage === "FLOOD") {
await new Promise((resolve) => setTimeout(resolve, error.seconds * 1000));
return trier();
}
})();
return { status: 200, reason: "success" };
} catch (er) {
context.logger.error(`Failed to handle event ${prop}`, { er });
await exit(1);
return { status: 500, reason: "failed" };
}
await exit(0);
})();
},
}

// we need to return the trier function here
return trier();
}
});
}

Expand Down

0 comments on commit cced343

Please sign in to comment.