Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
972 views
in Technique[技术] by (71.8m points)

javascript - Bot Framework V4 - TypeError: Cannot perform 'get' on a proxy that has been revoked

I am trying to make a rest query against a database that stores knowledge articles for users and returns an array of results based on what the user has searched for. Whenever I try to search I get:

"TypeError: Cannot perform 'get' on a proxy that has been revoked"

I have tried adding it to async as shown but I still keep getting the same error. Any idea what I am doing wrong?

const Response = async (turnContext) => {
    if (turnContext.activity.value.choice === 'feedbackProvider') {
        try {
            const feedbackBody = turnContext.activity.value.feedbackBody;
            const feedbackEmail = turnContext.activity.value.feedbackEmail;
            storage.write(feedbackBody, feedbackEmail);
            await turnContext.sendActivity(`Feedback Sent`);
        } catch (err) {
            console.log('fetch failed', err);
        }
    } else if (turnContext.activity.value.choice === 'issueRaiser') {
        try {
            const bugTitle = turnContext.activity.value.issueTitle;
            const bugDesc = turnContext.activity.value.issueDescription;
            const bugEmail = turnContext.activity.value.issueEmail;
            const request = require('request');
            request({
                method: 'Post',
                uri: `<uri>issues?title=${ bugTitle }&description=${ bugDesc } ${ bugEmail }&labels=bug`,
                json: true,
                headers: {
                    'Private-Token': '<token>'
                }
            });
            turnContext.sendActivity(`Issue Raised`);
        } catch (err) {
            console.log('fetch failed', err);
        }
    } else if (turnContext.activity.value.choice === 'knowledgeBaseSearch') {
        try {
            const knowledgeBaseTopic = turnContext.activity.value.knowledgeBaseTopic;
            request({
                url: process.env.SN_KB_URL + knowledgeBaseTopic,
                json: true,
                auth: {
                    'username': process.env.Ticket_User,
                    'password': process.env.Ticket_Key
                }
            }, async (error, response, body) => {
                try {
                    var stuff = [];
                    for (var i = 0, len = body.result.length; i < len; i++) {
                        stuff.push(
                            CardFactory.heroCard(body.result[i].short_description, ['imageUrl1'], [`${ process.env.SN_KB_Resp_URl }${ body.result[i].number }`])

                        );
                    }
                    let messageWithCarouselOfCards = MessageFactory.carousel(stuff);
                    await turnContext.sendActivity(messageWithCarouselOfCards);
                } catch (err) {
                    console.log(error);
                }
            });
        } catch (err) {
            console.log('fetch failed', err);
        }
    }
};

Full Error Message:

TypeError: Cannot perform 'get' on a proxy that has been revoked
cardMiddleware.js:35
    at Request.request [as _callback] (c:Botssdk4-2skillscardMiddleware.js:35:45)
    at Request.self.callback (c:Botssdk4-2
ode_modules
equest
equest.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (c:Botssdk4-2
ode_modules
equest
equest.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (c:Botssdk4-2
ode_modules
equest
equest.js:1085:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)

From my post on the forum I was informed that I was using a request module that did not support Promises, which I believe was causing my error. I've now began to use Axios for my request which is shown below;

try {
    return await axios.get(process.env.SN_KB_URL + knowledgeBaseTopic, {
        headers: {
          auth: {
          username: process.env.Ticket_User,
          password: process.env.Ticket_Key
        }
      }
    })
  }

However now when I run the request I get a 401 'Unauthorised' error and I'm not sure what is wrong with my request.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This issue happened because I was using a request module that did not support promises. Changing my request module for one that did support promises (which I found out about by using this article) resolved the issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...