TypeError: Cannot read property 'status' of undefined

I have performed the following steps within my Google Cloud Shell:

  1. npm i @codahq/packs-sdk -g
  2. coda init
  3. Copied the pack.ts content from this page “On your local machine - Coda Pack SDK
  4. Then I have added an API request to the pack.ts (the final code can be found below)
  5. coda execute pack.ts Hello “world”
  6. I see the following error message (pasted below)

If I copy the code into the browser pack studio, it works (screenshot attached).
So it seems that it has something to do with the SDK.

I would be grateful if someone could help, because local development seems to be faster.
Thank you in advance.

ERROR MESSAGE:

TypeError: Cannot read property ‘status’ of undefined
at Object.handleFetcherStatusError (/usr/local/nvm/versions/node/v12.14.1/lib/node_modules/@codahq/packs-sdk/dist/bundles/thunk_bundle.js:4709:21)
at (:12:15)
at async Object.handleErrorAsync (/usr/local/nvm/versions/node/v12.14.1/lib/node_modules/@codahq/packs-sdk/dist/bundles/thunk_bundle.js:4696:14)
at async Object.execute (…/…/home/johannes/ga-pack2/pack.ts:25:20)
at async Object.findAndExecutePackFunction (/usr/local/nvm/versions/node/v12.14.1/lib/node_modules/@codahq/packs-sdk/dist/bundles/thunk_bundle.js:4580:14)
{
message: “Cannot read property ‘status’ of undefined”,
name: ‘TypeError’
}

CODE:

import * as coda from “@codahq/packs-sdk”;
export const pack = coda.newPack();

pack.addNetworkDomain(“httpbin.org”);

pack.addFormula({
name: “Hello”,
description: “A Hello World example.”,

parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: “name”,
description: “The name you would like to say hello to.”,
}),
],

resultType: coda.ValueType.String,
execute: async function ([name], context) {
let payload = {
foo: “bar”,
};

let response = await context.fetcher.fetch({
  method: "POST",
  url: "https://httpbin.org/post",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),

});

const responseBody = JSON.stringify(response.body);

return "Hello " + responseBody;

},
});

2 Likes

This is due to the fact that by default coda execute doesn’t fetch real data, and returns an undefined response object. To enable that you need to include the --fetch flag. We are changing this behavior in the next release of the SDK, to make --fetch the default, but that release isn’t out yet.

1 Like

It is working. Many thanks :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.