Skip to content

Commit 5731cbd

Browse files
Merge pull request IPGeolocation#8 from real34/patch-1
Catch UncaughtException on JSON.parse call while parsing response from api.ipgeolocation.io.
2 parents 1bddd97 + 3804cb5 commit 5731cbd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

IPGeolocationAPI.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,13 @@ function postRequest(subUrl, urlParams = '', requestData = {}, callback) {
224224
'message': 'Internet is not connected!'
225225
};
226226
} else {
227-
jsonData = JSON.parse(this.responseText);
227+
try {
228+
jsonData = JSON.parse(this.responseText);
229+
} catch {
230+
jsonData = {
231+
'message': 'ipgeolocation.io seems to respond unexpectedly!'
232+
};
233+
}
228234
}
229235

230236
if (callback && typeof (callback) === typeof (Function)) {

0 commit comments

Comments
 (0)