From 169076dffadfd301c5080acdf191723f8abc107c Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Tue, 17 Jul 2018 23:27:07 +0200 Subject: [PATCH] Better error messages on geolocation fetching errors --- src/i18n/en.js | 4 ++++ src/i18n/fr.js | 4 ++++ src/views/Map.vue | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/i18n/en.js b/src/i18n/en.js index 6e67bcc..06a961a 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -17,8 +17,12 @@ export default { upvote: 'Upvote', }, geolocation: { + errorFetchingPosition: 'Error fetching your position:', fetching: 'Fetching current position…', geolocation: 'Geolocation', + permissionDenied: 'access to your position is denied.', + positionUnavailable: 'unable to retrieve your position.', + timeout: 'position was too long to acquire.', unavailable: 'Sorry, geolocation is not available in your browser.', }, intro: { diff --git a/src/i18n/fr.js b/src/i18n/fr.js index 28a8aaf..17fcec0 100644 --- a/src/i18n/fr.js +++ b/src/i18n/fr.js @@ -17,8 +17,12 @@ export default { upvote: 'Confirmer', }, geolocation: { + errorFetchingPosition: 'Impossible de récupérer votre position :', fetching: 'En attente de votre position…', geolocation: 'Géolocalisation', + permissionDenied: "l'accès a votre position a été refusé.", + positionUnavailable: 'impossible de déterminer votre position.', + timeout: 'votre position est trop longue à récupérer.', unavailable: "Désolé, la géolocalisation n'est pas disponible dans votre navigateur.", }, intro: { diff --git a/src/views/Map.vue b/src/views/Map.vue index db0836f..dbd208f 100644 --- a/src/views/Map.vue +++ b/src/views/Map.vue @@ -139,7 +139,14 @@ export default { } }, handlePositionError(error) { - this.error = `Error ${error.code}: ${error.message}`; + this.error = `${this.$t('geolocation.errorFetchingPosition')} `; + if (error.code === 1) { + this.error += this.$t('geolocation.permissionDenied'); + } else if (error.code === 2) { + this.error += this.$t('geolocation.positionUnavailable'); + } else { + this.error += this.$t('geolocation.timeout'); + } }, setPosition(position) { if (this.latLng) {