Node.js 在异步操作服务器上取消获取

Node.js 在异步操作服务器上取消获取,node.js,express,asynchronous,fetch,Node.js,Express,Asynchronous,Fetch,我有一个取回请求,比如 fetch(`http://localhost:4000/test`, { method: 'GET', mode: 'cors', cache: 'no-cache', headers: { 'Content-Type': 'application/json' } }) .then(result => console.log('success')) .catch(error => console.log('error', erro

我有一个取回请求,比如

fetch(`http://localhost:4000/test`, {
  method: 'GET',
  mode: 'cors',
  cache: 'no-cache',
  headers: {
    'Content-Type': 'application/json'
  }
})
.then(result => console.log('success'))
.catch(error => console.log('error', error));
以及用于请求的nodejs快速路由器(快速承诺路由器)

this.router.get('/test', (request: Request, response: Response) => {
  response.status(200).send({'status': 'ok'});
});
调用fetch时,将记录成功。那很好。 但是当我把nodejs路由器函数改为async时

this.router.get('/test', (request: Request, response: Response) => {
  return asyncFunction().then(result => response.status(200).send({'status': 'ok'}));
});
提取被取消,控制台日志显示
TypeError:Failed to fetch

当我使用浏览器URL或Postman调用/test api时,我得到了一个成功的结果。
我不明白为什么提取失败了。(也使用Axios进行了尝试,获得了相同的结果)。

我在获取问题上走错了方向。 该问题与提取无关,而是与调用提取的事件有关。
在方法的末尾,我需要一个event.preventDefault(),以便停止事件并正确处理提取

您是否已将路径从“/test”更改为“/login”?您在哪里调用fetch-inasyncFunction@ManjeetThakur不抱歉,这也是“/test”@YouBee异步函数只是一个例子。取回正在调用路由器url。由于路由器是一个明确承诺的路由器,使用邮递员(或浏览器URL)给出正确的响应应该不会有问题。