Skip to content

Commit f3fc455

Browse files
committed
added better location error handling
1 parent 56a1a94 commit f3fc455

File tree

3 files changed

+76
-62
lines changed

3 files changed

+76
-62
lines changed

dist/breinify-api.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15348,43 +15348,50 @@ dependencyScope.jQuery = $;;
1534815348
if (typeof geo !== 'object') {
1534915349
_self.foundGeoLocation = true;
1535015350
callback(null);
15351+
15352+
return;
1535115353
} else if (typeof permissions !== 'object') {
1535215354
_self.foundGeoLocation = true;
1535315355
callback(null);
15354-
} else {
1535515356

15356-
// any error should be caught here
15357-
try {
15357+
return;
15358+
}
1535815359

15359-
// check if the permission is already granted
15360-
permissions.query({name: 'geolocation'}).then(function (permission) {
15361-
if (permission.state === 'granted') {
15362-
geo.getCurrentPosition(
15363-
function (position) {
15364-
_self.foundGeoLocation = true;
15365-
_self.geoLocation = {
15366-
'accuracy': position.coords.accuracy,
15367-
'latitude': position.coords.latitude,
15368-
'longitude': position.coords.longitude,
15369-
'speed': position.coords.speed
15370-
};
15371-
15372-
callback(_self.geoLocation);
15373-
}, function () {
15374-
_self.foundGeoLocation = true;
15375-
callback(null)
15376-
}, {
15377-
'timeout': 150
15378-
});
15379-
} else {
15380-
_self.foundGeoLocation = true;
15381-
callback(null);
15382-
}
15383-
});
15384-
} catch (e) {
15360+
// any error should be caught here
15361+
try {
15362+
15363+
// check if the permission is already granted
15364+
permissions.query({name: 'geolocation'}).then(function (permission) {
15365+
if (permission.state === 'granted') {
15366+
15367+
geo.getCurrentPosition(
15368+
function (position) {
15369+
_self.foundGeoLocation = true;
15370+
_self.geoLocation = {
15371+
'accuracy': position.coords.accuracy,
15372+
'latitude': position.coords.latitude,
15373+
'longitude': position.coords.longitude,
15374+
'speed': position.coords.speed
15375+
};
15376+
15377+
callback(_self.geoLocation);
15378+
}, function () {
15379+
_self.foundGeoLocation = true;
15380+
callback(null)
15381+
}, {
15382+
'timeout': 150
15383+
});
15384+
} else {
15385+
_self.foundGeoLocation = true;
15386+
callback(null);
15387+
}
15388+
}).catch(e => {
1538515389
_self.foundGeoLocation = true;
1538615390
callback(null);
15387-
}
15391+
});
15392+
} catch (e) {
15393+
_self.foundGeoLocation = true;
15394+
callback(null);
1538815395
}
1538915396
}
1539015397
};

dist/breinify-api.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BreinifyUser.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,43 +113,50 @@
113113
if (typeof geo !== 'object') {
114114
_self.foundGeoLocation = true;
115115
callback(null);
116+
117+
return;
116118
} else if (typeof permissions !== 'object') {
117119
_self.foundGeoLocation = true;
118120
callback(null);
119-
} else {
120121

121-
// any error should be caught here
122-
try {
123-
124-
// check if the permission is already granted
125-
permissions.query({name: 'geolocation'}).then(function (permission) {
126-
if (permission.state === 'granted') {
127-
geo.getCurrentPosition(
128-
function (position) {
129-
_self.foundGeoLocation = true;
130-
_self.geoLocation = {
131-
'accuracy': position.coords.accuracy,
132-
'latitude': position.coords.latitude,
133-
'longitude': position.coords.longitude,
134-
'speed': position.coords.speed
135-
};
136-
137-
callback(_self.geoLocation);
138-
}, function () {
139-
_self.foundGeoLocation = true;
140-
callback(null)
141-
}, {
142-
'timeout': 150
143-
});
144-
} else {
145-
_self.foundGeoLocation = true;
146-
callback(null);
147-
}
148-
});
149-
} catch (e) {
122+
return;
123+
}
124+
125+
// any error should be caught here
126+
try {
127+
128+
// check if the permission is already granted
129+
permissions.query({name: 'geolocation'}).then(function (permission) {
130+
if (permission.state === 'granted') {
131+
132+
geo.getCurrentPosition(
133+
function (position) {
134+
_self.foundGeoLocation = true;
135+
_self.geoLocation = {
136+
'accuracy': position.coords.accuracy,
137+
'latitude': position.coords.latitude,
138+
'longitude': position.coords.longitude,
139+
'speed': position.coords.speed
140+
};
141+
142+
callback(_self.geoLocation);
143+
}, function () {
144+
_self.foundGeoLocation = true;
145+
callback(null)
146+
}, {
147+
'timeout': 150
148+
});
149+
} else {
150+
_self.foundGeoLocation = true;
151+
callback(null);
152+
}
153+
}).catch(e => {
150154
_self.foundGeoLocation = true;
151155
callback(null);
152-
}
156+
});
157+
} catch (e) {
158+
_self.foundGeoLocation = true;
159+
callback(null);
153160
}
154161
}
155162
};

0 commit comments

Comments
 (0)