使用POST方法以Ionic / Angular发布时失败

时间:2018-12-10 21:01:45

标签: angular ionic3 rxjs6

这个问题刚刚发生并开始像这样发生,无缘无故,显然根本没有任何原因。它只是无法完成从POST方法调用到Webservice的请求。

老实说,即使它现在正常工作,我也看不到代码中的任何问题。

最糟糕的是,在Chrome控制台中不会显示任何错误,只会显示失败的点:

polyfills.js:3 
XHR failed loading: OPTIONS "http://MY-SERVER:5000/profiles/set-logged-profile".

s @ polyfills.js:3
t.scheduleTask @ polyfills.js:3
onScheduleTask @ polyfills.js:3
t.scheduleTask @ polyfills.js:3
r.scheduleTask @ polyfills.js:3
r.scheduleMacroTask @ polyfills.js:3
(anonymous) @ polyfills.js:3
o.(anonymous function) @ polyfills.js:2
(anonymous) @ http.js:1630
Observable._trySubscribe @ Observable.js:43
Observable.subscribe @ Observable.js:29
(anonymous) @ subscribeTo.js:21
subscribeToResult @ subscribeToResult.js:11
MergeMapSubscriber._innerSub @ mergeMap.js:74
MergeMapSubscriber._tryNext @ mergeMap.js:68
MergeMapSubscriber._next @ mergeMap.js:51
Subscriber.next @ Subscriber.js:54
(anonymous) @ scalar.js:5
Observable._trySubscribe @ Observable.js:43
Observable.subscribe @ Observable.js:29
MergeMapOperator.call @ mergeMap.js:29
Observable.subscribe @ Observable.js:24
FilterOperator.call @ filter.js:15
Observable.subscribe @ Observable.js:24
MapOperator.call @ map.js:18
Observable.subscribe @ Observable.js:24
TakeUntilOperator.call @ takeUntil.js:17
Observable.subscribe @ Observable.js:24
webpackJsonp.620.HomePage.ionViewWillEnter @ home.ts:134
ViewController._lifecycle @ view-controller.js:486
ViewController._willEnter @ view-controller.js:384
NavControllerBase._willEnter @ nav-controller-base.js:780
(anonymous) @ nav-controller-base.js:673
t.invoke @ polyfills.js:3
onInvoke @ core.js:14191
t.invoke @ polyfills.js:3
r.run @ polyfills.js:3
NgZone.run @ core.js:14105
NavControllerBase._viewsWillLifecycles @ nav-controller-base.js:667
Animation._fireBeforeReadFunc @ animation.js:723
Animation._beforeAnimation @ animation.js:652
Animation._playDomInspect @ animation.js:346
requestAnimationFrame (async)
Platform.raf @ platform.js:538
(anonymous) @ animation.js:292
requestAnimationFrame (async)
Platform.raf @ platform.js:538
Animation.play @ animation.js:291
NavControllerBase._transitionStart @ nav-controller-base.js:605
(anonymous) @ nav-controller-base.js:533
t.invoke @ polyfills.js:3
onInvoke @ core.js:14191
t.invoke @ polyfills.js:3
r.run @ polyfills.js:3
(anonymous) @ polyfills.js:3
t.invokeTask @ polyfills.js:3
onInvokeTask @ core.js:14182
t.invokeTask @ polyfills.js:3
r.runTask @ polyfills.js:3
o @ polyfills.js:3
Promise.then (async)
r @ polyfills.js:3
t.scheduleTask @ polyfills.js:3
onScheduleTask @ polyfills.js:3
t.scheduleTask @ polyfills.js:3
r.scheduleTask @ polyfills.js:3
r.scheduleMicroTask @ polyfills.js:3
f @ polyfills.js:3
c @ polyfills.js:3
(anonymous) @ polyfills.js:3
Animation._didFinish @ animation.js:994
Animation._didFinishAll @ animation.js:981
onTransitionEnd @ animation.js:428
onTransitionEnd @ platform.js:610

我正在RxJs 6+和Angular 7+中使用,在发出POST请求的“服务”代码下方:

  public sendPost(url: string, payload: any, showLoading: boolean = true) {
    if (this.isConnected) {
      this.loadingStatus(showLoading);
      let endPoint: string = this.setEndPoint(url);
      let headers: any = this.requestHeaders();
      console.log('ENDPOINT: ' + endPoint);
      let observable$: Observable < any > = this.http.post(endPoint, payload, headers);
      observable$.pipe(
        retryWhen(genericRetryStrategy()),
        tap(() => {
          console.log("HTTP POST request executed and finished");
          this.loadingStatus(false);
        }),
        catchError(err => {
          this.loadingStatus(false);
          return throwError(err);
        }));
      return observable$;
    } else {
      return this.error$;
    }
  }

有人以前遇到过这样的情况吗?

1 个答案:

答案 0 :(得分:0)

发现了问题。

订阅时,我有一个“ takeUntil”,并且我将驱逐舰设置为可观察到的错误值:

this.destroy$.next(false); // changed to false
this.destroy$.complete(); // and added this

this.profileService.setLoginProfile(profieData, false)
  .pipe(takeUntil(this.destroy$))
  .subscribe((profile) => {
    this.help.preferences.profile = profile;

    this.help.tabEnabled = true;

    this.destroy$.next(true);

  }, error => {
    this.help.showToast(error.message);
  });