未处理的拒绝错误:发送标头后无法设置。为什么会这样呢?

时间:2018-10-25 00:00:32

标签: javascript node.js express

我不知道问题出在哪里...根据对这个错误的含义的研究,似乎我在某个地方发送了两次请求或发送了两次响应。我看不到正在发生的任何事情...

file1.js
 export const wrapper = (req, res, next) => {
  async function getValue(user) {
     await getExpiration(user).then(response => {
       if (response.condition) {
         return res.status(401).json()
       } 
     })
   }

   getValue(user)
 }

...

file2.js

export const getExpiration = async user => {
    return new Promise(function(resolve, reject) {
      getOrgInfo(user.org_id)
        .then(res => {
          return resolve(res)
        }).catch(err => reject(err))
    }).catch(err => console.log(err))
  }
}

...

file3.js

// this is a function that talks to my database and returns a promise
export const getOrgInfo = (org_id) => {
return kx('orgs').select('Expiration').where({'id': org_id})
}

2 个答案:

答案 0 :(得分:0)

您可以尝试以下方法吗?

 file1.js
 export const wrapper = async (req, res, next) => {      
     const response = await getExpiration(user);
       if (response.condition) {
         res.status(401).json()
       } else {
         next()
       }       
 }

答案 1 :(得分:0)

尝试直接调用它:

factory = gst_rtsp_media_factory_new ();
gst_rtsp_media_factory_set_launch (factory,
      "( rtspsrc location=rtsp://admin:Admin12345@192.168.1.126 ! rtph264depay ! h264parse ! rtph264pay pt=96 name=pay0 )");