Initially i was getting UnhandledPromiseRejectionWarning: TypeError: Cannot read property "distance" of undefined. to solve that error i have added a if condition with reject. now getting this error UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1). Any solutions ? here is my code
export function fun1(): Promise < survayResult > {
return new Promise((resolve, reject) => {
//..........
//..........
surveyDistance.forEach((result) => {
//
})
if(condition) {
reject(new Error("something went erong"));
return
}
let totalDistance = surveyDistance[0].distance;
// ...
//...
resolve("with some data");
})
}
surveyDistance[0]
doesn't exist. Not sure what you're trying to do there exactly, but it's more a logic issue than a Promise issue - non-network runtime errors should almost never happen – CertainPerformance