How can I reformat my API response using a callback function and access the data within the angular subscribe method?
I attempted to use mergemap but it didn't work as expected.
this.http.get('https://some.com/questions.xml', {headers, responseType: 'text'})
.mergeMap(
res => xml2js.parseString(
res,
{ explicitArray: false },
(error, result) => {
if (error) {
throw new Error(error);
} else {
console.log(result);
return result;
}
}
)
).subscribe(
data => { console.log("response", data); },
error => { console.log(error); }
);
My intention was to receive the response JSON in the subscribe method, however, I am encountering an error message that states: TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.