I am gathering data to set for a list of properties, however it calls many different services to help obtain this data. If there is a problem with any of the services it would throw an error. If an error is thrown I want the data to just return null for that specific property, and continue getting the rest of the data.
How do I do this without wrapping each service call in a try catch block?
I.E) this get all the properties, but if anything fails, the properties afterwards will not be set.
public async getAllProperties(){
try {
const [studentYear, numOfCourses, numOfSemesters, startDate, gradDate] =
await Promise.all([
studentService.getStudentYear(),
courseService.getNumOfCourses(),
semesterService.getNumOfSemesters(),
.... (etc)
])} catch (e){
console.log("error with getting Properties");
}
}
For example if I call getAllProperties() and the courseService throws an error, I want numOfCourses to be null, and for it to continue to check semesterService.getNumofCourse and continue setting the rest of the properties.
How can I do this without try catch for each service? I.E I don't want to write this for each property
try {
studentService.getStudentYear
} catch (e){
console.log("error in student Year");
studentYear = null;
}
try {
courseService.getNumOfCourses()
} catch (e){
console.log("error in get Num Of courses");
numOfCourses = null;
}
Thanks for any assistance or ideas!