Skip to content

Commit

Permalink
Merge pull request #673 from oneblink/ON-40638
Browse files Browse the repository at this point in the history
ON-40638 # capture error where permissions are not correct
  • Loading branch information
mymattcarroll authored May 24, 2024
2 parents 50f233e + b3d0938 commit bd19f0e
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/form-elements/FormElementGoogleAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,38 @@ function FormElementGoogleAddress({
input,
},
(predictions, status) => {
if (
status === google.maps.places.PlacesServiceStatus.ZERO_RESULTS
) {
resolve([])
return
}
if (status !== google.maps.places.PlacesServiceStatus.OK) {
reject('Google Places service not available')
return
switch (status) {
case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: {
resolve([])
break
}
case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {
reject(
new OneBlinkAppsError(
'Google Maps API key has not been configured correctly',
),
)
break
}
case google.maps.places.PlacesServiceStatus.OK: {
resolve(predictions ?? [])
break
}
default: {
reject(
new OneBlinkAppsError(
'An unknown error has occurred. Please contact support if the problem persists.',
),
)
}
}
resolve(predictions ?? [])
return
},
)
}).catch((e) => {
if (!abortSignal.aborted) {
Sentry.captureException(e)
}
throw new OneBlinkAppsError(
'An unknown error has occurred. Please contact support if the problem persists.',
{ originalError: e },
)
throw e
})

if (!abortSignal.aborted) {
Expand Down Expand Up @@ -148,7 +158,9 @@ function FormElementGoogleAddress({
!place
) {
reject(
`Could not find address details for place with id: ${placeId}`,
new OneBlinkAppsError(
`Could not find address details for place with id: ${placeId}`,
),
)
return
}
Expand All @@ -160,14 +172,7 @@ function FormElementGoogleAddress({
onChange(element, { value: place })
} catch (newError) {
if (isMounted.current) {
setError(
new OneBlinkAppsError(
'An unknown error has occurred. Please contact support if the problem persists.',
{
originalError: newError as Error,
},
),
)
setError(newError as Error)
}
}
if (isMounted.current) {
Expand Down Expand Up @@ -224,7 +229,7 @@ function FormElementGoogleAddress({
{error && (
<div role="alert" className="has-margin-top-8">
<div className="has-text-danger ob-error__text cypress-google-address-details-error-message">
{error.toString()}
{error.message}
</div>
</div>
)}
Expand Down

0 comments on commit bd19f0e

Please sign in to comment.