0

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

6
  • Try moving your let convertedAddress inside the try catch. Commented May 15, 2023 at 11:18
  • Sadly this didn't work :( Commented May 15, 2023 at 12:22
  • Do you use convertedAddress[0].y somewhere else perhaps in the template? I don't have problems catching undefined inside an electron app's try catch block. On another note you don't have any awaits inside your forEach loop, so I don't think that you need an async function there. You could check if convertedAddress[0] is undefined and then handle the error yourself, return the function and setup the error in your formgroup. Commented May 15, 2023 at 12:55
  • Nope, this is the only place where I use convertedAddress[0].y in the template... And thanks for the advide about the awaits in my loop Commented May 15, 2023 at 12:59
  • I think you need to either log the contents of convertedAddress[0] or attach a debugger before creating you latLng. I only see one place where you are calling .y referenced from the error, saying that probably your convertedAddress[0] is undefined, so you should try to look into what is happening there. But I agree an undefined error is strange inside a try catch block. electron should be able to handle that. Commented May 15, 2023 at 13:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.