TypeError: You provided 'undefined' where a stream was expected

前端 未结 10 671
广开言路
广开言路 2021-01-11 09:42

I have an Ionic app that has a user provider with a signup() method:

doSignup() {
  // set         


        
相关标签:
10条回答
  • 2021-01-11 10:01

    I did face this issue and in my case responseType suppose to be text (because of designed API end-point) rather than default json.

    import { HttpClient } from '@angular/common/http';

    Before:

    getToken(tokenCommand) {
        return this.http.post(API_BASE_URL + 'user/token', tokenCommand);
    }
    

    After fixed:

    getToken(tokenCommand) {
        return this.http.post(API_BASE_URL + 'user/token', tokenCommand
                                                         , { responseType: 'text' });
    }
    

    I think this error message is too general and it will be nice if it's developers could provide more detail/helpful error message. Thanks.

    0 讨论(0)
  • 2021-01-11 10:01

    It happened to me doing unit-test on watch mode. Stop the build, trigger it again = the error is gone.

    0 讨论(0)
  • 2021-01-11 10:06

    I had the same error and typical scenario was that I was returning different actions based on certain condition. But handling of one condition was missing and I was not returning anything under my effects. That's when this issue came up. It's always better to have a default return action to avoid such instances.

    ...mergeMap((res: FetchWorkflowStatusResponse) => {
       if(this){
          return action1
       } else if(that){
          return action2
       }
    }
    

    Now if some value other than this and that comes then there will not be any return statement and the error will be thrown.

    0 讨论(0)
  • 2021-01-11 10:12

    I faced this issue when creating a new project using generator-jhipster-ionic (yo jhipster-ionic giving v3.1.2), following Matt Raible's (OP) Use Ionic for JHipster to Create Mobile Apps with OIDC Authentication blog article, but choosing JWT authentication instead of OIDC.

    The origin of the issue was a mix of problems.

    I had the issue when running a Ionic app with the livereload server, CORS issues happening and Angular HTTP returning the classic HTTP failure response for (unknown url): 0 Unknown Error, where 0 is the HTTP error code. However, in the current case the issue was hidden by bad error handling at the Observable level.

    When you follow Angular's HttpClient #Error Details section advices, and add an Observable pipe with a catchError operator on the HTTP POST call, you can get the proper HTTP error details. In this case, instead of going down to the rxjs/util/subscribeToResult.js:71 (TS source #L80) TypeError: You provided 'undefined' where a stream was expected default error case, it goes to rx/util/subscribeToResult.js:23 (TS source #L34), and the error is handled properly in the piped method.

    After following the Observable calls, I found that the current default authentication interceptor, as seen in this template src/providers/auth/auth-interceptor.ts catches HTTP error 401 and does nothing for the others, basically muting them and preventing their propagation.

    TL;DR In the JWT case, the solution is to simply remove the src/providers/auth/auth-interceptor.ts .catch(...) block, allowing error propagation to login.service.ts, and in its this.authServerProvider.login(credentials).subscribe((data) => { ... }, (err) => { ... }) error callback.

    I believe the issue and solution could be the same for your OIDC case, its signup method, and error callback.

    [Edit] Even more since the same .catch code can be found in the starter example mentioned in the first post comments: ionic-jhipster-starter - auth-interceptor.ts#L31

    0 讨论(0)
  • 2021-01-11 10:13

    In my case I was returing with empty return:

    if (...)
       return; // problem here
    

    To fix, I returned the observed object:

    if (...)
       return req.next();
    
    0 讨论(0)
  • 2021-01-11 10:19

    In my case I was neglecting to return an Action in my NgRx Effect. I had a conditional statement which was only returning an Action on one condition.

    0 讨论(0)
提交回复
热议问题