I am writing angular service class to hit APIs. When some Internal server error comes in response, I want to send error message to user. The services written for get, but giving this error.
core.js:6014 ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. at subscribeTo (subscribeTo.js:40:1)
sample.component.ts
this.maintenanceService.getCurrentStatus(this.Id, fromDateToRest,
toDateToRest).subscribe(
(CurrentStatus: any) => {
if (CurrentStatus && CurrentStatus.length > 0) {
//do something
}
if (CurrentStatus && CurrentStatus.length == 0) {
this.errorMessage = "No data!"
}
if (CurrentStatus && CurrentStatus.status == 500) {
this.errorMessage = "Internal Server Error!"
}
else {
this.errorMessage = "Vehicle not found!"
}
}
);
sample.service.ts
getCurrentStatus(Id: String, fromDateToRest:String, toDateToRest:String): Observable<any> {
let params;
params = Object.assign( { fromDateToRest, toDateToRest } )
const httpOptions = {
params
}
return this.restService.get<any>(URL,httpOptions);
}
restService
get<T>(url: string, httpOptions?: {}) {
return this.httpClient.get<T>(url , httpOptions);
}
I read same questions and still didn't get a solution.