gpt4 book ai didi

javascript - Reactjs isomorphic-fetch PATCH 怎么有body错误?

转载 作者:行者123 更新时间:2023-12-02 14:35:55 24 4
gpt4 key购买 nike

所以基本上我是用 f​​etch POST 或 PATCH 方法发送数据,当我遇到错误时,我可以在网络中看到 -> 响应此错误:

{
"Errors": [
{
"Code": -201,
"Message": "Could not get file from link",
"AssociatedError": "404 Not Found"
}
],
"Result": null
}

这是我的实际代码:

function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
}

export function sendImageUploaded(data, valueMethod, endpoint) {
return dispatch => {
dispatch(requestPosts(data));
return fetch(endpoint, {
method: valueMethod,
headers: new Headers({
Authorization: Isengard.config.token
}),
body: data
})
.then(checkStatus)
.then(reponse => {
dispatch(successSent("The output list has been successfully sent!"));
}).catch(err => {
console.log('request failed', err);
dispatch(failSent("Error on sending request: " + err));
});
};
};

我正在努力解决这个错误消息。

最佳答案

您已在“error.response”中收到响应错误。您只需履行该 promise 即可。

而不是

.catch(err => {
console.log('request failed', err);
dispatch(failSent("Error on sending request: " + err));
});

使用

.catch(err => {
err.response.json().then((json) =>{
let {Errors,Result} = json;
dispatch(failSent(Errors)); // You are sending your array of errors here
});
});

关于javascript - Reactjs isomorphic-fetch PATCH 怎么有body错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37456937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com