UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): TypeError: Cannot read property 'status' of undefined
玩家域节点js代码
const express = require('express');
const axios = require('axios');
const mime = require('mime-types');
const router = express.Router();
const ResponseUtil = require('../../utils/ResponseUtil');
router.get('/:rank/:jump', (req, res, next) => {
const { originalUrl } = req;
//console.log(" originalUrl ", originalUrl);
const mode = req.params.rank;
const value = encodeURIComponent(req.params.jump);
console.log("document 4--->", mode);
console.log("for document Testing--->", mode);
const url = `players/?id=890900-weweew`;
axios
.get(url, {
headers: {
authorization: req.headers.authorization,
},
})
.then((response) => {
console.log("document--->", response);
const file = Buffer.from(response.data.content, 'base64');
const fileType = mime.contentType(response.data.contentInfo.fileType);
const fileExtension = response.data.contentInfo.fileType.toLowerCase();
const fileName = `filename=${response.data.contentInfo.id}.${fileExtension}`;
res.set('Content-Type', fileType);
res.set('Content-disposition', `attachment; ${fileName}`);
res.send(file);
})
.catch((e) => {
res.status(e.response.status).send(e.response.data);
});
ResponseUtil.callService(res, url);
});
module.exports = router;
运动域节点js代码
const express = require('express');
const router = express.Router();
const ResponseUtil = require('../../utils/ResponseUtil');
router.get('/:rank/:jump', (req, res, next) => {
const { originalUrl } = req;
//console.log(" originalUrl ", originalUrl);
const mode = req.params.rank;
const value = encodeURIComponent(req.params.jump);
const url = `/sports?mode=sdioiosdio`;
console.log("rank 3--->", mode);
console.log("for document Testing--->", mode);
ResponseUtil.callService(res, url);
});
module.exports = router;
答案 0 :(得分:0)
根据axios document,您对url
的要求没有完成。
也许目的地无法到达。
因此,如文档所述,最佳的错误处理是检查错误的response
的可用性。
...
.catch((e) => {
if(e.response){
return res.status(e.response.status).send(e.response.data);
}
res.status(500).send(e.message || 'Something wrong');
});