Skip to content

Commit

Permalink
Prevent infinite recursion in response tag
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Sep 16, 2024
1 parent 75df5f8 commit 29d2d0e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/template-function-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const plugin: Plugin = {
if (httpRequest == null) {
return null;
}
const renderedHttpRequest = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose });

const responses = await ctx.httpResponse.find({ requestId: httpRequest.id, limit: 1 });

Expand All @@ -57,6 +56,8 @@ export const plugin: Plugin = {

// Send if no responses and "smart," or "always"
if ((behavior === 'smart' && response == null) || behavior === 'always') {
// NOTE: Render inside this conditional, or we'll get infinite recursion (render->render->...)
const renderedHttpRequest = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose });
response = await ctx.httpRequest.send({ httpRequest: renderedHttpRequest });
}

Expand Down

0 comments on commit 29d2d0e

Please sign in to comment.