My trigger step is set to HTTP body only, and a custom response.
Below that I have the following code in my node.js site:
export default defineComponent({
async run({ steps, $ }) {
// Access the ‘section’ variable from the request body
const section = steps.trigger.event.section;
// Check if ‘section’ is defined
if (typeof section !== ‘undefined’) {
// ‘section’ is defined, proceed with your logic
// Await the $.respond() call
await $.respond({
status: 200,
headers: {
“Content-Type”: “application/json”,
“Access-Control-Allow-Origin”: “https://digital.ch1-consulting.com”
},
body: { section: section }
});
} else {
// ‘section’ is not defined, handle the error
console.error(“Error: ‘section’ variable not found in request body.”);
// Await the $.respond() call
await $.respond({
status: 500,
body: { error: “‘section’ variable not found” }
});
}
}
});
After deployment everything seems to be working per the screenshot below:
However, on my webpage I am receive the raw HTML of the success page instead of the custom response of “section” per the console log in Chrome: “Error fetching data: SyntaxError: Unexpected token [raw HTML from success page] is not valid JSON (anonymous)”
It seems like you’re encountering an issue with the response format being returned from your Pipedream workflow. The error message “Unexpected token ‘<’” suggests that your webpage is receiving an HTML response instead of the expected JSON.
Here are a few steps to troubleshoot and resolve this issue:
Ensure Custom Response is Enabled: Double-check that your HTTP trigger is configured to allow custom responses. In the Pipedream UI, make sure the “Return a custom response from your workflow” option is selected in the HTTP Response section of your HTTP trigger.
Verify Response Content-Type: Ensure that the Content-Type header in your $.respond() call is correctly set to application/json. This is already present in your code, but it’s worth verifying that this header is being sent correctly.
Check for Errors in the Workflow: Make sure there are no errors in your workflow that might cause it to return an HTML error page. You can add logging to your workflow to debug and ensure that the logic is executing as expected.
Inspect the Network Request: Use the browser’s developer tools to inspect the network request and response. This can help you verify the actual content being returned by the workflow and ensure that it’s in the expected JSON format.
Test with a Simple Response: As a test, try simplifying the response to see if the issue persists. For example, you can temporarily change the response to a simple JSON object:
Verify Deployment: Ensure that the latest version of your workflow is deployed and that there are no caching issues on your server or client-side that might be serving an outdated response.
If the issue persists after following these steps, consider reaching out to Pipedream support for further assistance: Support - Pipedream. They can provide more detailed help based on your specific setup and logs.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double-check my answers and code! Learn how to build your own.