Skip to content

Commit 6524944

Browse files
committed
fix process error types when obtaining user location
1 parent b909098 commit 6524944

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Explicitly set prettier tab-width
66
- Move release guide from README.md to RELEASE_GUIDE.md
7+
- Enhanced error processing for obtaining user location
78
- [The next improvement]
89

910
#### 8.7.10 - 2024-11-29

lib/ReactViews/Map/MapNavigation/Items/MyLocation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class MyLocation extends MapNavigationItemController {
153153
});
154154
}
155155

156-
handleLocationError(err: any) {
156+
handleLocationError(err: GeolocationPositionError) {
157157
const t = i18next.t.bind(i18next);
158158
let message = err.message;
159159
if (message && message.indexOf("Only secure origins are allowed") === 0) {
@@ -162,12 +162,19 @@ export class MyLocation extends MapNavigationItemController {
162162
const uri = new URI(window.location);
163163
const secureUrl = uri.protocol("https").toString();
164164
message = t("location.originError", { secureUrl: secureUrl });
165+
} else if (err.code === err.PERMISSION_DENIED) {
166+
message = t("location.permissionDenied");
167+
} else if (err.code === err.POSITION_UNAVAILABLE) {
168+
message = t("location.positionUnavailable");
169+
} else if (err.code === err.TIMEOUT) {
170+
message = t("location.timeout");
165171
}
166172
this.terria.raiseErrorToUser(
167173
new TerriaError({
168174
sender: this,
169175
title: t("location.errorGettingLocation"),
170-
message: message
176+
message: message,
177+
showDetails: false
171178
})
172179
);
173180
}

wwwroot/languages/en/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
"myLocation": "My Location",
6464
"location": "Location",
6565
"originError": "Your browser can only provide your location when using HTTPS. You may be able to use {{secureUrl}} instead.",
66-
"centreMap": "Centre map at your current location"
66+
"centreMap": "Centre map at your current location",
67+
"permissionDenied": "Permission denied to get your location. Please check your browser settings.",
68+
"positionUnavailable": "Your location information is unavailable.",
69+
"timeout": "Obtaining your location information took to long. Please try again later."
6770
},
6871
"splitterTool": {
6972
"errorTitle": "Failed to compare catalog item.",

0 commit comments

Comments
 (0)