Javascript 获取API中的消息属性';s捕捉函数
请允许我问一个可能很简单的问题。有人能告诉我Javascript 获取API中的消息属性';s捕捉函数,javascript,promise,Javascript,Promise,请允许我问一个可能很简单的问题。有人能告诉我fetchAPI末尾catch函数中参数err的message属性来自哪里吗?例如,在下面的代码片段中 fetch('exmaple.json') .then(response => response.json()) .then(json => randomlyMadeFunction()) .catch(err => console.log('Fetch problem: ' + err.message)); 我知道f
fetch
API末尾catch函数中参数err
的message
属性来自哪里吗?例如,在下面的代码片段中
fetch('exmaple.json')
.then(response => response.json())
.then(json => randomlyMadeFunction())
.catch(err => console.log('Fetch problem: ' + err.message));
我知道fetch返回一个Promise
,最后catch
函数将拒绝原因作为参数,在本例中为err
。我搜索了许多文章,但我无法找出err
的message
属性的来源。任何解释或暗示都将不胜感激
提前感谢。如果在
获取期间发生错误,则异常
或类型错误
将传递给捕获
回调,请参阅:
abortorror
由于调用了AbortController
方法abort()
方法,请求被中止
TypeError
指定的URL字符串包括用户凭据。应使用授权提供此信息
标题
是Error
s,因此具有message
属性,请参阅。console.log(JSON.Stringify(err))。您可以在控制台中看到所有键及其值