【发布时间】:2022-09-27 19:07:30
【问题描述】:
如果您考虑以下代码
React.useEffect(() => {
Auth.currentUserInfo()
.then((data) => {
if (data.username) {
//do something with data
}
})
.catch((error) => console.log(\'No logged in user\'))
}, [])
当我查看我的控制台时,我看到所有这些都与我的控制台日志混合在一起。
[ERROR] 14:14.682 AuthClass - No current user
at node_modules/@aws-amplify/core/lib-esm/Logger/ConsoleLogger.js:115:9 in prototype._log
at node_modules/@aws-amplify/core/lib-esm/Logger/ConsoleLogger.js:192:18 in <anonymous>
at node_modules/@aws-amplify/auth/lib-esm/Auth.js:2097:38 in user.confirmPassword$argument_2.onFailure
No logged in user
Error: ENOENT: no such file or directory, open \'/Users/XXXXX/react-native-discord/http:/192.168.50.85:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false\'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at getCodeFrame (/Users/XXXXX/react-native-discord/node_modules/metro/src/Server.js:949:18)
at Server._symbolicate (/Users/XXXXX/react-native-discord/node_modules/metro/src/Server.js:1022:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Server._processRequest (/Users/XXXXX/react-native-discord/node_modules/metro/src/Server.js:429:7) {
errno: -2,
syscall: \'open\',
code: \'ENOENT\',
path: \'/Users/XXXXX/react-native-discord/http:/192.168.50.85:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false\'
}
Error: ENOENT: no such file or directory, open \'/Users/XXXXX/react-native-discord/http:/192.168.50.85:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false\'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at getCodeFrame (/Users/XXXXX/react-native-discord/node_modules/metro/src/Server.js:949:18)
at Server._symbolicate (/Users/XXXXX/react-native-discord/node_modules/metro/src/Server.js:1022:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Server._processRequest (/Users/XXXXX/react-native-discord/node_modules/metro/src/Server.js:429:7) {
errno: -2,
syscall: \'open\',
code: \'ENOENT\',
path: \'/Users/XXXXX/react-native-discord/http:/192.168.50.85:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false\'
}
try/catch 或 catch() 似乎都没有发现错误。我怎样才能更好地处理错误而不会在我的控制台和设备中爆炸?
标签: javascript reactjs typescript react-native aws-amplify