After running my code, I encountered the following console log error: "'Missing required 'page' parameter".
I attempted to set this as a parameter in my get request, and it seemed successful because I was able to view the params as an array in the console log.
However, despite this, I am still receiving the error message. What could I be missing?
Attached is a photo of the console for reference:
Thank you in advance!
Service:
export class StoriesService implements OnInit {
private apiUrl = 'https://dev-api.byrd.news/v1/stories';
constructor(private http: Http) {
console.log("Yo! Stories!")
}
ngOnInit() { }
getToken() {
return Observable.fromPromise(firebase.auth().currentUser.getIdToken(true)
.then((idToken) => {
return idToken;
}))
}
getData(page: string, feed: string, hits: string): Observable<any> {
return this.getToken()
.flatMap(idToken => {
let headers = new Headers();
headers.append('user_token', idToken);
let params = new HttpParams()
.set('page', page)
.set('feed', feed)
.set('hits', hits);
let options = new RequestOptions({ headers: headers, params: params });
// console.log(this.idToken, options);
console.log("Token: " + idToken);
console.log(headers, params);
return this.http
.get(this.apiUrl, { params, headers })
.map((response: Response) => {
console.log("Breakthrough!")
return response.json() || {};
})
})
.catch(this.handleError);
}
private handleError(error: Response) {
return Observable.throw(error.statusText);
}
Component:
getStories() {
this.storiesService.getData('0', 'latest', '6')
.subscribe(data => {
console.log(data);
console.log("No more data available.")
})
}
Edit: I have noticed that the URL I receive has unusual looking params. Could this be due to them being unparsed?
""