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

前端 未结 20 1106
时光说笑
时光说笑 2020-12-01 06:22

I am trying to map from a service call but getting an error. Looked at subscribe is not defined in angular 2? and it said that in order to subscribe we need to

相关标签:
20条回答
  • 2020-12-01 06:49

    This error happened to me @angular 7

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

    The error is actually self-explanatory, it says somewhere in the observable I pass the invalid object. In my case, there was lots of API call but all the calls were failing because of wrong server configuration. I tried to use map, switchMap, or other rxjs operator but the operators are getting undefined objects.

    So double-check your rxjs operator inputs.

    0 讨论(0)
  • 2020-12-01 06:51

    I have been facing this issue when trying to authenticate a user using JSON Web Token. in my case it's related to authentication interceptor.

    Sending a request to authenticate a user doesn't have to provide a token since it doesn't exist yet.

    Check that your interceptor include this:

    if (req.headers.get('No-Auth') == "True")
                return next.handle(req.clone());
    

    And that you provide {'No-Auth':'True'} to your header's request like this:

      authenticateUser(user): Observable<any> {
        const headers = new HttpHeaders({'No-Auth':'True'});
        headers.append('Content-Type', 'application/json');
        return this.httpClient.post(`${this.apiEndpoint}/auth/authenticate`, user, {headers: headers});
      }
    
    0 讨论(0)
提交回复
热议问题