Skip to content

Commit 4df3336

Browse files
author
Krzysztof Borowy
committed
multiGet to propagate errors
1 parent 8dfd16d commit 4df3336

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/AsyncStorage.native.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,27 @@ const AsyncStorage = {
282282
return value;
283283
});
284284
const reqLength = getRequests.length;
285+
286+
/**
287+
* As mentioned few lines above, this method could be called with the array of potential error,
288+
* in case of anything goes wrong. The problem is, if any of the batched calls fails
289+
* the rest of them would fail too, but the error would be consumed by just one. The rest
290+
* would simply return `undefined` as their result, rendering false negatives.
291+
*
292+
* In order to avoid this situation, in case of any call failing,
293+
* the rest of them will be rejected as well (with the same error).
294+
*/
295+
const errorList = convertErrors(errors);
296+
const error = errorList && errorList.length ? errorList[0] : null;
297+
285298
for (let i = 0; i < reqLength; i++) {
286299
const request = getRequests[i];
287300
const requestKeys = request.keys;
301+
if (error) {
302+
request.callback && request.callback(error);
303+
request.reject && request.reject(error);
304+
continue;
305+
}
288306
const requestResult = requestKeys.map((key) => [key, map[key]]);
289307
request.callback && request.callback(null, requestResult);
290308
request.resolve && request.resolve(requestResult);

0 commit comments

Comments
 (0)