Circular Json in on request

amazon-alexa

#1

Hi
i need load data from url before launch because i wish to set global array from ours data event

but i have this error

     Error -----------------------------------------------------------------
  
  Message:
  Converting circular structure to JSON
      --> starting at object with constructor 'ClientRequest'
      |     property 'socket' -> object with constructor 'TLSSocket'
      --- property '_httpMessage' closes the circle
  
  Stack:
  TypeError: Converting circular structure to JSON
      --> starting at object with constructor 'ClientRequest'
      |     property 'socket' -> object with constructor 'TLSSocket'
      --- property '_httpMessage' closes the circle
      at JSON.stringify (<anonymous>)
      at stringify (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/express/lib/response.js:1123:12)
      at ServerResponse.json (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/express/lib/response.js:260:14)
      at /home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/jovo-framework/src/hosts/ExpressJS.ts:45:18
      at new Promise (<anonymous>)
      at ExpressJS.setResponse (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/jovo-framework/src/hosts/ExpressJS.ts:43:12)
      at Alexa.response (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/jovo-platform-alexa/src/Alexa.ts:188:30)
      at Middleware.run (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/jovo-core/src/core/Middleware.ts:85:11)
      at App.handle (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/jovo-core/src/core/BaseApp.ts:291:7)
      at App.handle (/home/sylvain/sap/sap_tdd_jovo_2020-08-15_1000/node_modules/jovo-framework/src/App.ts:333:5)

and script use

  async ON_REQUEST() {
    const todayFormat = new Date().toLocaleString("fr-FR", {
      year: "numeric",
      month: "2-digit",
      day: "2-digit"
    });
    const url = 'https://localhost:3000';
    this.$session.$data.sapEvent = await HttpService.get(url);
  },
  LAUNCH() {
    const title = this.$session.$data.sapEvent.data.data[0].title
    let speech = "bienvenue sur SAP, voulez sortir ? " + title;
    let reprompt = 'nom d une sortie ou une categorie.';
    this.ask(speech, reprompt);
  },

how to avoid this issue ?


#2

is the good practice to store in session datas use from all intent ?
or need to save in $user ?

this.$session.$data.sapEvent


#3

Maybe this is helpful:

I would only store the relevant data to the session object as it can get quite large easily.


#4

but in document


you write store in this.$data
but how to retrieve this on unit testing ?


#5

I’m not sure if I understand what you mean. We always recommend to only store the relevant data to the session data, not everything that it returned by an API.


#6

Please only store data to the $session object that is serializable. In your case it would be something like that:

const response = await HttpService.get(url);

if (response.status === 200) {
     this.$session.$data.sapEvent = response.data
}


#7

I receive all data fetch from API, for read a list of items ( exemple : list of tasks)

so I fetch once


#8

I see autopilot from twilio not work with session


#9

The response object is really bloated with data you don’t need. The data from the API is (usually) stored in response.data.