When trying to send a response within a promise with
(onrejected) => {
return res.send(
this.visualization.loadJsonData(
'src/data/Softwarecomponent/Chromium Sample Analysis.json',
),
);
},
my StreamableFile Object won't get serialized as a JSON Object. I just get a bunch of information. I am not sure why this happen
controller file:
@Get()
findSofwareComponentByProject(
@Query('project') project: any,
@Headers('API_KEY') apiKey: string,
@Res() res: Response,
) {
// throw new DataNotFoundException();
const data = this.visualization.findSoftwareComponentByProject(
apiKey,
project,
);
data
.then(
(onfulfill) => {
console.log('fullfilled 1');
},
(onrejected) => {
return res.send(
this.visualization.loadJsonData(
'src/data/Softwarecomponent/Chromium Sample Analysis.json',
),
);
},
)
.catch((err) => console.log('Something is not working', err));
return data;
}
service file: visualization.service.ts
// Testing method to return JSON data
loadJsonData(path: string) {
const file = createReadStream(join(process.cwd(), path));
return new StreamableFile(file);
}
