Why does running my script trigger a "HTTP interface cannot respond to this request" error message?

This topic was automatically generated from Slack. You can find the original thread here.

when i run the following script I get a message in the console Logs “HTTP interface can not respond to this request, check http.customResponse setting”
Can you check this script and advise why?

import { axios } from "@pipedream/platform";
import crypto from "crypto";

export default defineComponent({
  props: {
    http: {
      type: "$.interface.http",
      customResponse: true,
    },
    secure_token: {
      type: "string",
      label: "Secure Token",
    },
  },
  async run({ event }) {
    console.log("Event:", event);  // Log the entire event object

    const { method, query } = event;
    console.log("Method:", method);  // Log the HTTP method
    console.log("Query:", query);  // Log the query parameters

    if (method === "GET" && query.crc_token) {
      const crc_token = query.crc_token;
      const hmac = crypto.createHmac("sha256", this.secure_token);
      hmac.update(crc_token);
      const value = hmac.digest("base64");

      const response = {
        status: 200,
        body: {
          crc_response: value,
        },
        headers: {
          "content-type": "application/json",
        },
      };

      console.log("Sending response:", response);  // Log the response

      try {
        this.http.respond(response);
      } catch (error) {
        console.log("Error in sending response:", error);  // Log any errors
      }
    } else {
      const errorResponse = {
        status: 400,
        body: {
          error: "Invalid request",
        },
        headers: {
          "content-type": "application/json",
        },
      };

      console.log("Sending error response:", errorResponse);  // Log the error response

      try {
        this.http.respond(errorResponse);
      } catch (error) {
        console.log("Error in sending error response:", error);  // Log any errors
      }
    }
  },
});

I noticed an issue in your code. You’re using && instead of && in your conditional statement. Please update the line: if (method === "GET" && query.crc_token) { to: ```
if (method === “GET” && query.crc_token) {

This was a response I got earlier as well - and from here just gets to a dead end!

ah gotcha, you actually don’t want to use the $.interface.http prop, you should use $.respond instead: https://pipedream.com/docs/workflows/steps/triggers/#using-custom-code-with-respond