【发布时间】:2020-10-21 01:46:45
【问题描述】:
我正在使用 Express 路由开发自定义集成解决方案,在对 firebase 进行 fetch 调用后,我需要对我的服务器的响应是来自 firebase 的响应,以向我显示来自于的任何问题(例如身份验证错误)在那里。
我一直在尝试使用 res.send() 来显示响应,但它会抛出“TypeError:将循环结构转换为 JSON”错误,但是当 console.logging 相同的响应时,它会给我正确的响应(这是一个身份验证错误)。这有什么关系?
代码如下:
router.route("/bankval").get (fetchAirtabeleRecords, (req, res) => {
fetch(`https://xxxxxxxxxxxx.firebaseio.com/integratedData.json?auth=${FIREBASESECRET}`,{
method: 'PUT',
headers:
{
Authorization: 'Bearer ' + FIREBASESECRET,
'Content-Type': 'application/json'
},
body: JSON.stringify({bankValuation: res.bankVal}) // correct values here
})
.then((res) => res.json())
.then(res.send(res)) // This throws me the error
.then((res)=> { console.log('response: ', res); }) // This works and displays expected "error: 'Unauthorized request.' from firebase, but it's only in console, so it's not good enough."
// .then(res.send({bankValuation: res.bankVal})) // this works, but if authentication error occurs it still displays the correct data, when it's obviously not sent to firebase. Only using this for testing purposes.
.catch(err=> { console.log('error: ',err); }) })
我对此很陌生,所以也许我完全倒退了或其他什么,但感谢任何输入。
谢谢。
【问题讨论】: