我的代码已经过测试,可以在Debug版本上运行,但是当我转到Release时,它在加载时崩溃。我从XCode收到以下错误:
E0729 10:19:44.701792 1833381888 JSCHelpers.cpp:140] Got JS Exception: Can't find variable: fetch (/var/containers/Bundle/Application/FC98F3E8-A8D3-499E-A419-AB5C296E2B2F/mothership.app/main.jsbundle:312)
没有下面的代码,它可以工作,但是我不明白为什么不能。正在使用它来刷新我的App.js文件顶部的身份验证令牌:
global.refresh_count = 0;
global._fetch = fetch;
global.fetch = function(uri, options, ...args) {
return global._fetch(uri, options, ...args).then(async (response) => {
console.log('Fetch', { request: { uri, options, ...args }, response });
if (response.status == 401 && global.refresh_count <= 3) {
// get refresh token
global.refresh_count++;
const response = await identityServices.refreshToken();
// try request again
if (response.access) {
// set new authorization
var newAuthHeader = 'Bearer ' + response.access;
options.headers.Authorization = newAuthHeader;
const repeatResponse = await fetch(
uri,
options,
...args,
);
return repeatResponse;
} else {
console.log('could not refresh token!!!');
}
}
global.refresh_count = 0;
return response;
});
};