NodeJS Axios是否在构建期间抛出错误中止信号?

v8wbuo2f  于 2022-11-03  发布在  Node.js
关注(0)|答案(1)|浏览(92)

我试图在nodejs typescript项目中使用axios,在构建过程中,它引发了错误abortSignal任何针对此问题的修复,感谢帮助
index.ts

export async function getAccessToken(apiConfig: any) {

        const req = {
            grant_type: apiConfig.authOptions.body.grant_type,
            client_id: apiConfig.authOptions.credentials.clientId,
            client_secret: apiConfig.authOptions.credentials.clientSecret,
            scope: apiConfig.authOptions.body.scope
        };
        const headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "appName": "Blink"
        };
        try {
            const resp: AxiosResponse = await axios.post('https://test.com//auth/oauth2/token',
            req, { headers });
            console.log(resp.data);
        } catch (err) {
            // Handle Error Here
            console.error(err);
        }
    }

错误

node_modules/axios/index.d.ts(93,12): error TS2304: Cannot find name 'AbortSignal'.

Package.json

"axios": "^0.24.0",
h7appiyu

h7appiyu1#

尝试在axios参数中提供abortController信号:

const abortController=new AbortController;
const resp: AxiosResponse = await axios.post(
  'https://test.com//auth/oauth2/token',
  req,
  { headers },
  signal:abortController.signal
);

相关问题