Angular 4 - Http request error: You provided 'undefined' where a stream was expected

前端 未结 2 861
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 05:19

While trying to do a HTTP Post request I am receiving the following error:

auth.service.ts?c694:156 Something went wrong requesting a new password, erro

2条回答
  •  孤城傲影
    2021-02-14 05:51

    I had a very similar issue. It also ended up being a problem with an HTTP interceptor. I had an automatic deserialization function running on all responses with a particular API endpoint pattern. Responses which weren't instances of HTTPResponse ended up being eaten. Adding an else statement which returned the response untouched when not an instance of HTTPResponse solve the issue for me:

    @Injectable()
    export class DeserializerInterceptor implements HttpInterceptor {
      public intercept(request: HttpRequest, next: HttpHandler): Observable> {
        return next.handle(request).map(
          event => {
            if (event instanceof HttpResponse) {
              let response = event as HttpResponse;
              // ... deserialization of response object
              return response;
            } else {
              return event; // ... adding this else statement fixed the `undefined` error.
            }
          }
        );
      }
    }
    

    (Removed error handling code, for clarity.)

提交回复
热议问题