Skip to content

Commit 7827fde

Browse files
leeyehwangxiao
authored andcommitted
fix(File): only catch User.current() exception in React Native (#335)
1 parent f4e1d95 commit 7827fde

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/file.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,12 @@ module.exports = function(AV) {
355355
} else if (!AV._config.disableCurrentUser) {
356356
try {
357357
owner = AV.User.current();
358-
} catch (e) {
359-
console.warn('Get current user failed. It seems this runtime use an async storage system, please new AV.File in the callback of AV.User.currentAsync().');
358+
} catch (error) {
359+
if ('SYNC_API_NOT_AVAILABLE' === error.code) {
360+
console.warn('Get current user failed. It seems this runtime use an async storage system, please create AV.File in the callback of AV.User.currentAsync().');
361+
} else {
362+
throw error;
363+
}
360364
}
361365
}
362366

src/localstorage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ if (!localStorage.async) {
2929
_(syncApiNames).each(function(apiName) {
3030
if (typeof localStorage[apiName] !== 'function') {
3131
localStorage[apiName] = function() {
32-
throw new Error('Synchronous API [' + apiName + '] is not available in this runtime.');
32+
const error = new Error('Synchronous API [' + apiName + '] is not available in this runtime.');
33+
error.code = 'SYNC_API_NOT_AVAILABLE';
34+
throw error;
3335
};
3436
}
3537
});

0 commit comments

Comments
 (0)