I've developed various services to interact with different APIs. The post services seem to be functioning, but an error keeps popping up:
ERROR TypeError: You provided 'undefined' where a stream was expected. Options include Observable, Promise, Array, or Iterable. at subscribeTo (subscribeTo.js:27)
The same type of error is encountered with the GET services, however, no data is retrieved in return. Below is one of the services:
GetClientData(): Observable<ClientDto> {
let url_ = this.baseUrl + "https://xxxxxxxxxxxxxxxx/getClients";
url_ = url_.replace(/[?&]$/, "");
let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Accept": "application/json"
})
};
return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => {
return this.processGetAllPermissions(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processGetAllPermissions(<any>response_);
} catch (e) {
return <Observable<ClientDto>><any>_observableThrow(e);
}
} else
return <Observable<ClientDto>><any>_observableThrow(response_);
}));
}
protected processGetAllPermissions(response: HttpResponseBase): Observable<ClientDto> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(<any>response).error instanceof Blob ? (<any>response).error : undefined;
let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }};
if (status === 200) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 ? ClientDto.fromJS(resultData200) : new ClientDto();
return _observableOf(result200);
}));
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}));
}
return _observableOf<ClientDto>(<any>null);
}
Cloud Function
exports.getClients = functions.https.onRequest((req, res) => {
res.set('Access-Control-Allow-Origin', 'http://localhost:4200');
res.set('Access-Control-Allow-Methods', 'GET', 'POST');
res.set('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.end();
}
else
{
let allClients = [];
usersClients.get()
.then(snapshot => {
snapshot.forEach(doc => {
allClients.push(doc.data());
});
res.send(200, {
"data": allClients
})
})
.catch(err => {
console.log("Error getting data", err);
});
}
});