Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught User Exception (!articles.length) #7

Open
Surinder95 opened this issue Aug 18, 2021 · 8 comments
Open

Uncaught User Exception (!articles.length) #7

Surinder95 opened this issue Aug 18, 2021 · 8 comments

Comments

@Surinder95
Copy link

line 18, 44, 74 in the alanStudio.js file throw uncaught exceptions
I changed the condition to
if(articles === undefined)
but that just routed to error to line 17 in NewsCards.js where we display the 4 cards on the main page after trying to evaluate if(!articles.length)

I don't know why this error keeps popping up. Clearly, the articles aren't being returned hence the reason its properties are showing up as undefined. But my API key and plan are functioning well and I haven't surpassed any query limits so this is a pretty annoying issue. Please let me know if there's a way around this. It would be very appreciated as I spent a lot of time developing this and not just copying and pasting. Would be a shame if I had to drop it after all the hours spent.

@Martin-droid
Copy link

Encountered The Same Issue

@Martin-droid
Copy link

Did you find a Solution?

@Surinder95
Copy link
Author

Surinder95 commented Nov 2, 2021 via email

@Pooreffects
Copy link

Moving on it is

@Mudassir55
Copy link

// News by Source
intent('Give me (the|) news from $(source* (.))','news from $(source (.*))', (p) => {
let NEWS_API_URL = https://newsapi.org/v2/top-headlines?apiKey=${API_KEY};

if(p.source.value) {
    NEWS_API_URL = `${NEWS_API_URL}&sources=${p.source.value.toLowerCase().split(" ").join('-')}`
}

api.request(NEWS_API_URL,{headers: {"user-agent": 'user agent' }}, (error, response, body) => {
    const { articles } = JSON.parse(body);
    
    if(!articles.length) {
        p.play('Sorry, please try searching for news from a different source');
        return;
    }
    
    savedArticles = articles;
    
    p.play({ command: 'newHeadlines', articles });
    p.play(`Here are the (latest|recent) ${p.source.value} news.`);

    p.play('Would you like me to read the headlines?');
});

})
May be this code will help you guys

@Mudassir55
Copy link

if this doesnot work then try
// News by Source
intent('Give me (the|) news from $(source* (.))','news from $(source (.*))', (p) => {
let NEWS_API_URL = https://newsapi.org/v2/top-headlines?apiKey=${API_KEY};

if(p.source.value) {
    NEWS_API_URL = `${NEWS_API_URL}&sources=${p.source.value.toLowerCase().split(" ").join('-')}`
}

api.request(NEWS_API_URL,{headers: {"user-agent": 'user agent' }}, (error, response, body) => {
    const { totalResults, articles } = JSON.parse(body);
    
    if(totalResults==0) {
        p.play('Sorry, please try searching for news from a different source');
        return;
    }
    
    savedArticles = articles;
    
    p.play({ command: 'newHeadlines', articles });
    p.play(`Here are the (latest|recent) ${p.source.value} news.`);

    p.play('Would you like me to read the headlines?');
});

})

@Mudassir55
Copy link

if this still doesnot work then try with both same codes but change the parameter in
oncommand:(commandData, articles)
use the same syntax and change command to commandData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@Surinder95 @Martin-droid @Pooreffects @Mudassir55 and others