HTTP request not returning an observable? Browser throwing error: 'You provided an invalid...

Discussão em 'Angular' iniciado por Jordan, Dezembro 3, 2024.

  1. Jordan

    Jordan Guest

    first post here!

    I have some logic that requires 2 nested API calls - so I decided to use switchMap. But the app doesn't think the second API call is an observable. The project lives in a monorepo, but the weird thing is that the code executes fine on the other projects...

    Error: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.

    Here is a simple use of switchMap that I'm trying to run on my project

    const { http } = this;
    const url = `URL1`;

    http.get<any>(url).pipe(
    switchMap(res => {
    console.log('call 1 finished')
    return http.get<any>('URL2')
    }),
    ).subscribe(val => {
    console.log('successful operation', val);
    })


    The subscription never executes. But if I wrap the second http call in of, the code will pass but the subscription output (val) is an observable.

    Any other reasons (angular project setup, http interceptors) that could cause this? There is also some AngularJS code/downgrade code being run at start Using Angular 18 and RXJS 7.

    Continue reading...

Compartilhe esta Página