Troubleshooting Forge API call

Hi all,
I’m playing around with Forge and attempting to create a trigger-based app that posts issue events to a third-party service. I have it working but I’m running into a weird issue that appears to be unique to the forge development environment.

Here’s the function I’m running when an issue is created:

import api from "@forge/api";

// stuff

async function handleIssueCreated(event) {
	const timestamp = event.issue.fields.updated;
	console.log('Posting ISSUE_CREATED event');
	const res = await api.fetch(PUSH_ENDPOINT, {
		method,
		headers,
		body: {	
			event: "ISSUE_CREATED",
			timestamp,
			...event
		},
	});
	console.log('hello');
}

The “hello” console.log statement never executes when running forge tunnel. The API call succeeds and I see the event being posted to my service, but it appears as if anything after api.fetch is not run.

There’s a non-zero chance I’m missing something blindingly obvious here. Any ideas?

I’m wondering if it’s a case of the node event structure ending too early. Can you add a return statement at the end?

Failing that - do you get different behavior with tunnel versus deployed?

Does the log show in the Developer Console?

Like @danielwester, I also vaguely remember something about triggered events discarding the return. Since the log is the last function it may be treating this as the return. You might try adding a return null statement.

UPDATE: Reference, “If a function invoked from a scheduled trigger returns a value, it is ignored. If the function throws an error, nothing will happen, and the function invocation will not be retried.”

2 Likes