在成功的API Post -Axios上捕获错误



我的传说成功地将文件附加到API上,但是它仍然遇到错误,告诉用户附件没有上传。我的控制台日志还显示了捕获量。

这是我的代码...这里显然有任何错误?

const postFileUpload = async (payload) => {
    let data = {};
    var accessToken = gapi.auth.getToken().access_token; // Here gapi is used for retrieving the access token.
    try {
        const { id, campDate, type, file } = payload;
        const formData = new FormData();
        formData.append('file', file);
        formData.append('type', type);
        if (campDate !== undefined) {
            formData.append('campDate', campDate);
        }
        formData.append('id', Id);
        const response = await axios.post(
            `https://${API_ENDPOINT}/attachments`,
            formData,
            {
                headers: {
                    'Content-Type': 'multipart/form-data',
                    'Authorization': 'Bearer ' + accessToken
                }
            }
        );
        console.log('SUCCESS!!');
        if (!response.success) {
            throw new Error(response.erorrMessage);
        }
        data = response.data;
        return data;
    } catch (error) {
        console.log('FAILURE!!', error);
        console.error('Error uploading attachment');
        throw new Error(error);
    }
}

您确定后呼叫的响应具有.success属性?

我将检查状态代码。