INSR-8688: More awaits and broader try/catch for google places API calls

This commit is contained in:
Alex Humphries 2026-03-05 10:31:41 -05:00
parent a1cdf7b630
commit 52645df56c
2 changed files with 13 additions and 16 deletions

View file

@ -13,10 +13,7 @@ import { useMainStore } from '@/store/index.js';
/** @ignore */
function setupMocks({
storeData,
props,
isShallowMount = true,
querySelectorFunction,
geocoderResult = ['1234 Test Street']
props
}) {
const mountOptions = getMountOptions({
router: {

View file

@ -158,9 +158,9 @@ export default {
async beforeRouteEnter(to, from, next) {
const cmsContent = await fetchCmsContentForPage(to.query.issPage);
next((vm) => {
next(async (vm) => {
vm.setCmsContent(cmsContent);
vm.setupAddressLookup();
await vm.setupAddressLookup();
});
},
data() {
@ -272,10 +272,10 @@ export default {
this.address2 = '';
this.city = '';
},
setupAddressLookup() {
async setupAddressLookup() {
const apiKey = applicationConfig.GOOGLE_PLACES_API_KEY;
this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=Function.prototype`)
await this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=Function.prototype`)
.catch(() => {
// Failed to fetch script
window.console.warn('Unable to load Google Places API script');
@ -283,15 +283,15 @@ export default {
},
geocodeAddress() {
const autoCompletePromise = new Promise((resolve, reject) => {
// Get Autocomplete Service
const acService = new window.google.maps.places.AutocompleteService();
// Get Places Service, needs psuedo element (or a map)
const placeService = new window.google.maps.places.PlacesService(document.createElement('div'));
// Create Autocomplete Session token, multiple requests one pricing hit
const acSessionToken = new window.google.maps.places.AutocompleteSessionToken();
const addressValue = `${this.address}, ${this.city}, ${this.state} ${this.zipCode}`;
try {
// Get Autocomplete Service
const acService = new window.google.maps.places.AutocompleteService();
// Get Places Service, needs pseudo element (or a map)
const placeService = new window.google.maps.places.PlacesService(document.createElement('div'));
// Create Autocomplete Session token, multiple requests one pricing hit
const acSessionToken = new window.google.maps.places.AutocompleteSessionToken();
const addressValue = `${this.address}, ${this.city}, ${this.state} ${this.zipCode}`;
acService.getPlacePredictions(
{
input: addressValue,