Smart Action doesn't work

My smart action doesn’t work

Observed behavior

forest/places.js:
{
name: ‘Télécharger le fichier comptable’,
type: ‘single’,
download: true
}


routes/places.js:
router.post(‘/actions/telecharger-le-fichier-comptable’, permissionMiddlewareCreator.smartAction(), (request, response) => {
const place_id = request.body.data.attributes.ids[0];
models.places.findByPk(place_id).then(place => {
superagent
.get(http://localhost:8084/files/${place.sergicIdFull})
.end((err, res) => {
response.setHeader(‘Content-Type’, res.header[‘content-type’]);
response.setHeader(‘Content-disposition’, res.header[‘content-disposition’]);
response.setHeader(‘Access-Control-Expose-Headers’, ‘Content-Disposition’);
response.send(res.body);

  });

});
});

Failure Logs

C:\Users\SELATMANI\BIbenFA\routes\places.js:757
response.setHeader(‘Content-Type’, res.header[‘content-type’]);
^

TypeError: Cannot read properties of undefined (reading ‘header’)
at C:\Users\SELATMANI\BIbenFA\routes\places.js:757:49
at Request.callback (C:\Users\SELATMANI\BIbenFA\node_modules\superagent\lib\node\index.js:905:3)
at ClientRequest. (C:\Users\SELATMANI\BIbenFA\node_modules\superagent\lib\node\index.js:822:12)
at ClientRequest.emit (node:events:526:28)
at Socket.socketErrorListener (node:_http_client:442:9)
at Socket.emit (node:events:526:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

Context

  • Project name: Sergic
  • Team name: gestion
  • Environment name: development
  • Agent (forest package) name & version: v8
  • Database type: Postgres
  • Recent changes made on your end if any: No changes

Hi Soufiane,

The “end” method only sends the request, to use the returned result, you need to call “then” instead:
.then((res) => /*use the response here*/)
You may also use async/await. Please refer to this documentation: https://www.npmjs.com/package/superagent#usage

Have a nice day,
Enki