Skip to content

Commit

Permalink
improved error handling?
Browse files Browse the repository at this point in the history
  • Loading branch information
andz-bb committed Apr 27, 2023
1 parent 6e85b02 commit fdbe4ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geolocation",
"version": "0.3.1",
"version": "0.3.2",
"description": "A form field that provides the user's current geolocation",
"author": "andz-bb",
"license": "MIT",
Expand Down
10 changes: 6 additions & 4 deletions src/Component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let latitude = "";
let longitude = "";
let position = "";
let error = "";
let isLoading = false;
let latFieldState;
let latFieldApi;
Expand All @@ -24,20 +24,19 @@
async function getLocation() {
if (!navigator.geolocation) {
// fieldApi.setError("Geolocation is not supported by your browser");
error = "Geolocation is not supported by your browser";
} else {
isLoading = true;
navigator.geolocation.getCurrentPosition(
(pos) => {
latitude = pos.coords.latitude;
longitude = pos.coords.longitude;
// position = `Latitude: ${latitude}, Longitude: ${longitude}`;
latFieldApi.setValue(latitude);
longFieldApi.setValue(longitude);
isLoading = false;
},
(err) => {
// fieldApi.setError(`Error(${err.code}): ${err.message}`);
error = `Error(${err.code}): ${err.message}`;
isLoading = false;
}
);
Expand Down Expand Up @@ -116,6 +115,9 @@
{#if !latitudeField || !longitudeField}
<div class="error">Please select a field</div>
{/if}
{#if error}
<div class="error">{error}</div>
{/if}
{#if latFieldState?.error}
<div class="error">{latFieldState.error}</div>
{/if}
Expand Down

0 comments on commit fdbe4ab

Please sign in to comment.