I try to create a function that returns values from the server, if one of the values returns with an error then everything that comes back to me from the function falls and I get NULL,
If I use try / catch the problem is solved.
What is the best solution in terms of performance and something that can work in the result I want
public async getUserById(id: number): Promise<dto> {
const arr = [];
const user = await this.userService.getUserById(id);
try {
const company = await this.companyService.getCompanyIdToken(
user.company_id
);
UsersProvider.setUserCompany(user, company);
for (const space of user.spaces) {
try {
const Response = await this.companyService.getSpaceById(space);
arr.push(Response);
} catch (error) {
console.log(error) **// Here I expect you not to throw an error**
}
}
} catch (error) {
console.log(error) **// Here I expect you not to throw an error**
}
return user;
}