So I have this Angular app that I've made for my company with a working web version but they've asked me to make it into a .exe app so I've searched for solutions. That's where I learned about Electron, I installed it and managed to make a .exe of my application but the problem is that there was a part of my code that's not working and it's about a try...catch block that's not working, wether it is here or not I would get a "Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'y')".
const Client: Client = this.model.LatLongFromFormContent;
let convertedAddress = await this.provider.search({query: ""+Client.Adresse+","+Client.CP+" "+Client.Ville});
let latLngClient: any;
try{
latLngClient = L.latLng(convertedAddress[0].y, convertedAddress[0].x);
let closestAgency: string = "";
let distanceClosestAgency: number = 500;
AgencyList.forEach(async agency =>{
let distance = (latLngClient.distanceTo(L.latLng(agency.GPS[0], agency.GPS[1]))/1000);
if (distance <= distanceClosestAgency){
closestAgency = agency.Num_agence+" - "+agency.VILLE;
distanceClosestAgency = distance
}
})
this.model.distanceToClosestAgency = Math.round(distanceClosestAgency *100)/100;
this.model.closestAgency = closestAgency;
}catch (error){
this.model.formGroup.controls['CP'].setErrors({'incorrect': true})
this.model.formGroup.controls['Ville'].setErrors({'incorrect':true})
}
If the error is caught, we're supposed to have a message appear on screen when a div is set to visible
<div *ngIf="model.formGroup.controls['CP'].invalid && model.formGroup.controls['Ville'].invalid && model.formGroup.controls['CP'].value != null" class="mt-2 alert alert-danger">
Vérifiez que le code postal et la ville correspondent bien.
</div>
but this is not happening, instead I have the error I pointed out earlier...
Any help would be appreciated
let convertedAddressinside the try catch.convertedAddress[0].ysomewhere else perhaps in the template? I don't have problems catchingundefinedinside an electron app's try catch block. On another note you don't have any awaits inside yourforEachloop, so I don't think that you need anasyncfunction there. You could check ifconvertedAddress[0]is undefined and then handle the error yourself, return the function and setup the error in your formgroup.convertedAddress[0].yin the template... And thanks for the advide about the awaits in my loopconvertedAddress[0]or attach adebuggerbefore creating you latLng. I only see one place where you are calling.yreferenced from the error, saying that probably yourconvertedAddress[0]is undefined, so you should try to look into what is happening there. But I agree anundefinederror is strange inside a try catch block. electron should be able to handle that.