Skip to content

Commit 25f3dcb

Browse files
committed
Updates in caching in session storage. And other minor updates.
1 parent 1f2d350 commit 25f3dcb

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

ipgeolocation.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,20 @@ const _ipgeolocation = function() {
121121
if (asyncCall) {
122122
fetch(url, requestOptions)
123123
.then((response) => {
124-
if (!response.ok) {
125-
callback(JSON.parse("{'status': ".concat(response.status, ", 'message': '", json.message, "'}")));
126-
}
127-
128124
return response.json();
129125
})
130-
.then((json) => {
131-
if (useSessionStorage) {
126+
.then((json) => {
127+
if (useSessionStorage && !json.message) {
132128
cacheInSessionStorage(subUrl, json);
133129
}
134-
130+
135131
callback(json);
136132
});
137133
} else {
138134
const response = await fetch(url, requestOptions);
139135
const json = await response.json();
140136

141-
if (!response.ok) {
142-
callback(JSON.parse("{'status': ".concat(response.status, ", 'message': '", json.message, "'}")));
143-
}
144-
145-
if (useSessionStorage) {
137+
if (response.ok && useSessionStorage) {
146138
cacheInSessionStorage(subUrl, json);
147139
}
148140

@@ -151,7 +143,7 @@ const _ipgeolocation = function() {
151143
} catch (error) {
152144
console.error(error);
153145

154-
callback(JSON.parse("{'status': 400, 'message': 'Something went wrong while query ipgeolocation.io API. If the error persists, contact us at support@ipgeolocation.io'}"));
146+
callback(JSON.parse("{'status': 400, 'message': 'Something went wrong while querying ipgeolocation.io API. If the error persists, contact us at support@ipgeolocation.io'}"));
155147
}
156148
}
157149

0 commit comments

Comments
 (0)