我正在运行http服务器,它始终返回504:
const express = require('express')
const app = express()
app.get('/', (req, res) => {
console.log('I AM HERE');
res.status(504).send('Not found!!');
})
app.listen(3000, () => console.log('Listening on port 3000!'))
之后,我正在做请求,使用got进行5次重试:
const got = require('got');
(async () => {
try {
const response = await got('http://localhost:3000/', {retries: 5});
console.log(response.body);
} catch (error) {
console.log(error.response.body);
}
})();
我期待,铭文I AM HERE
将被记录5次,但它只记录一次。我的代码出了什么问题?
答案 0 :(得分:0)
该参数为重试不重试,这里是工作示例
try {
const response = await got('https://example.com', {retry: 2});
return response.body
} catch (error) {
console.log(error.response.body);
return error
}