简体   繁体   中英

Eslint Error - Expected to return a value in arrow function

I am correcting some errors which are eslint related and I am getting the following error:

在此处输入图像描述

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;
 });
};

The code works fine but I am unsure as to where the return statement is required. Can anybody help?

ESlint is telling you that you are not returning anything async in that function. You are missing the return while waiting for axios.post

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

It looks like is working because you are calling the API, but the handling of the Promise is actually incorrect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM