markeh / NewsReader

0 stars 1 forks source link

Fix javascript error - promise undefined #4

Closed goofballLogic closed 6 years ago

goofballLogic commented 6 years ago
  1. Remove the conditional declaration of the promise - was causing javascript error in block out side referencing it
  2. Users can search for empty string (to clear search criteria) Fixes #3
markeh commented 6 years ago

Hi,

Your alteration allows the search function to be called with an empty query value, when the querystring is constructed by newsService.searchNews function it looks like the below:

http://YOUR_API:5000/api/news/gb/from=2018-01-17&q=&sortBy=popularity

The webAPI endpoint this querystring is used with constructs the following request to retrieve data from NewsAPI:

https://newsapi.org/v2/everything?from=2018-01-17&q=&sortBy=popularity&apiKey=API_KEY

Unfortunately that request produces the following error with NewsAPI as the q key requires a value:

{"status":"error","code":"parametersMissing","message":"Required parameters are missing, the scope of your search is too broad. Please set any of the following required parameters and try again: q, sources, domains."}

You can add a pair of quotes to declare an empty value but this will return 0 results:

https://newsapi.org/v2/everything?from=2018-01-17&q=""&sortBy=popularity&apiKey=API_KEY

{"status":"ok","totalResults":0,"articles":[]}`

In the case of an empty search query it might be better to call the refreshNews() function in the main controller to return the view to a non search state?

goofballLogic commented 6 years ago

ok i'll cancel this pull request and try again.