Eslint 错误 - 预期在箭头函数中返回一个值

时间:2020-12-21 16:58:02

标签: javascript eslint

我正在纠正一些与 eslint 相关的错误,但出现以下错误:

enter image description here

const fileApiLink = process.env.FILE_API_LINK;
const downloadSingleReportAxios = async (id, downloadFile, downloadURL) => {
 const url = fileApiLink.toString();
  await axios
   .post(url, {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data: {
    urlLink: downloadURL,
    fileName: downloadFile
  }
})
.then(response => {
  return response.data;
})
.catch(error => {
  if (error.response) {
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
    return console.log(error.response.status);
  } else if (error.request) {
    // The request was made but no response was received
    // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
    // http.ClientRequest in node.js
    return console.log(error.request);
  }
  // Something happened in setting up the request that triggered an Error
  console.log('Error', error.message);

  console.log(error.config);
  throw error;
 });
};

代码工作正常,但我不确定哪里需要 return 语句。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

ESlint 告诉您在该函数中您没有返回任何 async。您在等待 axios.post 时错过了返回

return await axios.post(url, ...);

看起来可以正常工作,因为您正在调用 API,但是 Promise 的处理实际上是错误的。