title: Angular 4 - Http request error: You provided 'undefined' where a stream was expected
body: <p>While trying to do a HTTP Post request I am receiving the following error:</p>
  
  <blockquote>
    <p>auth.service.ts?c694:156 Something went wrong requesting a new
    password, error message: You provided 'undefined' where a stream was
    expected. You can provide an Observable, Promise, Array, or Iterable.</p>
  </blockquote>
  
  <p>The Http request is preceded by another one, which works perfectly fine.</p>
  
  <p>My component calling the service:</p>
  
  <pre><code>requestNewPassword(formInput: NgForm) {
       if(formInput.controls['email'].value != '')
        this.authService.getApplicationAccessToken()
        .mergeMap((response: IAuthAppResponse) =&gt; this.authService.requestNewPassword(formInput, response.access_token))
        .subscribe(response =&gt; {
          // Content removed for simplicity
        })
      }
  </code></pre>
  
  <p>The service method throwing the error:</p>
  
  <pre><code>public requestNewPassword(formData: NgForm, applicationAccessToken: string): Observable&lt;any&gt; {
        let headers = new HttpHeaders({
          'Authorization':'Bearer ' + applicationAccessToken
        });
        let email: string = formData.controls['email'].value;
        const body = {
          email: email
        };
  
        console.log('requestNewPassword call header: ' + headers.get('Authorization'));
        console.log('Email: ' + body.email);
  
        return this.http.post(this.baseUrl + '/api/user/password/forgot', body, {headers}).do(response =&gt; {
          console.log("New password was successfully sent to the e-mail adress");
        }).catch((error: HttpErrorResponse) =&gt; {
          console.log('Something went wrong requesting a new password, error message: ' + error.message);
          return Observable.throw(error);
        })
      }
  </code></pre>
  
  <p>Whenever I enter an email in the form and submit, which in turn triggers the requestNewPassword method of the component, I receive the error mentioned above from the service.</p>
  
  <p>The header and email are logged correctly so I don't think there's anything with the data I am providing.</p>
  
  <p>Since I have no idea how to debug this, I thought it was a good idea to post this as a question on this incredible platform.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Update</strong></p>
  
  <p>I minimized the code in my component to narrow down the problem by not chaining the two HTTP requests but only call the second one, that is causing trouble.</p>
  
  <pre><code>requestNewPassword(formInput: NgForm) {
        if(formInput.controls['email'].value != '')
        this.authService.requestNewPassword(formInput, "")
         .subscribe(response =&gt; {
           // Content removed for simplicity
         })
       }
  </code></pre>
  
  <p>I now get a full stack trace:</p>
  
  <pre><code>ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
      at Object.subscribeToResult (subscribeToResult.js?c011:74)
      at MergeMapSubscriber._innerSub (mergeMap.js?e2a2:132)
      at MergeMapSubscriber._tryNext (mergeMap.js?e2a2:129)
      at MergeMapSubscriber._next (mergeMap.js?e2a2:112)
      at MergeMapSubscriber.Subscriber.next (Subscriber.js?215e:89)
      at ScalarObservable._subscribe (ScalarObservable.js?d097:49)
      at ScalarObservable.Observable._trySubscribe (Observable.js?4e06:172)
      at ScalarObservable.Observable.subscribe (Observable.js?4e06:160)
      at MergeMapOperator.call (mergeMap.js?e2a2:87)
      at Observable.subscribe (Observable.js?4e06:157)
      at FilterOperator.call (filter.js?35ab:60)
      at Observable.subscribe (Observable.js?4e06:157)
      at MapOperator.call (map.js?c4af:56)
      at Observable.subscribe (Observable.js?4e06:157)
      at DoOperator.call (tap.js?7fa8:63)
      at Observable.subscribe (Observable.js?4e06:157)
      at CatchOperator.call (catchError.js?0867:79)
      at Observable.subscribe (Observable.js?4e06:157)
      at PasswordResetComponent.requestNewPassword (passwordReset.component.ts?c169:43)
      at Object.eval [as handleEvent] (PasswordResetComponent.html:7)
      at handleEvent (core.js?223c:13255)
      at callWithDebugContext (core.js?223c:14740)
      at Object.debugHandleEvent [as handleEvent] (core.js?223c:14327)
      at dispatchEvent (core.js?223c:9704)
      at eval (core.js?223c:12028)
      at SafeSubscriber.schedulerFn [as _next] (core.js?223c:4235)
      at SafeSubscriber.__tryOrUnsub (Subscriber.js?215e:238)
      at SafeSubscriber.next (Subscriber.js?215e:185)
      at Subscriber._next (Subscriber.js?215e:125)
      at Subscriber.next (Subscriber.js?215e:89)
      at EventEmitter.Subject.next (Subject.js?c1c6:55)
      at EventEmitter.emit (core.js?223c:4203)
      at NgForm.onSubmit (forms.js?ad57:5710)
      at Object.eval [as handleEvent] (PasswordResetComponent.html:7)
      at handleEvent (core.js?223c:13255)
      at callWithDebugContext (core.js?223c:14740)
      at Object.debugHandleEvent [as handleEvent] (core.js?223c:14327)
      at dispatchEvent (core.js?223c:9704)
      at eval (core.js?223c:10318)
      at HTMLFormElement.eval (platform-browser.js?023b:2614)
      at ZoneDelegate.invokeTask (zone.js?fad3:425)
      at Object.onInvokeTask (core.js?223c:4620)
      at ZoneDelegate.invokeTask (zone.js?fad3:424)
      at Zone.runTask (zone.js?fad3:192)
      at ZoneTask.invokeTask [as invoke] (zone.js?fad3:499)
      at invokeTask (zone.js?fad3:1540)
      at HTMLFormElement.globalZoneAwareCallback (zone.js?fad3:1566)
  </code></pre>
  
  <p>Since this mentions the html, I will provide the html code aswell:</p>
  
  <pre><code>&lt;form class="custom_form" #requestNewPasswordForm="ngForm" (ngSubmit)="requestNewPassword(requestNewPasswordForm)"&gt;
      &lt;label&gt;E-mail&lt;/label&gt;
      &lt;input class="custom_input" type="email" class="inputfield form-control" ngModel name="email"&gt;
      &lt;button class="btn btn-default" type="submit"&gt;
        Send
      &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>