我正在使用此处指定的本机提取库。似乎每当返回 200 OK 以外的响应时,它都会引发字符串 response 异常Uncaught (in promise) TypeError: Failed to fetch。
有没有办法在特定的 HTTP 响应代码上捕获和分支并仍然查看响应数据?例如 401 响应?
我附上了我用作获取包装器的请求代码。
static request(url, data) {
let headers = {
"Authorization": window.localStorage.getItem("Authorization"),
"Content-Type": "application/json"
};
let options = {
method: "GET",
headers: headers,
mode: "no-cors",
cache: "no-cache",
};
if (data) {
options = {
method: "POST",
headers: headers,
mode: "no-cors",
cache: "no-cache",
body: JSON.stringify(data)
}
}
return new Promise(async (resolve, reject) => {
try {
let response = await fetch(url, …Run Code Online (Sandbox Code Playgroud) 我已经完成了以下步骤,使用我们的git repo设置ssh部署密钥,以便能够在没有用户名和密码的情况下进行git pull:
注意:我在AWS EC2/Ubuntu 14.04.3上
ssh-keygen -t rsa -b 4096 -C "ownersEmail@gmail.com"这些然后保存为〜/ .ssh中的id_rsa和id_rsa.pub /sudo git pull git@github.com:ownersUsername/OurRepo.git并获得以下错误权限被拒绝(publickey).致命:无法从远程存储库读取.
请确保您具有正确的访问权限并且存储库存在.
另请注意:此存储库在其他用户帐户下是私有的.
此外,当我尝试ssh git@github.com我得到:
您好userName /回购!您已成功通过身份验证,但GitHub不提供shell访问权限.与github.com的连接已关闭.
部署密钥随着使用而出现.现在已经讨论了这个问题超过4个小时,非常感谢,谢谢.