private createRequest()

in src/app/services/http/http.service.ts [84:122]


  private createRequest(method: RequestMethod, url: string, body?: any, options?: RequestOptionsArgs, silent?: boolean): Observable<any> {
    return this.store.select(fromRoot.getAuthenticationState)
      .take(1)
      .map(state => this._buildRequestOptions(method, url, body, state.tenant, state.username, state.authentication.accessToken, options))
      .flatMap(requestOptions => {
        this.process.next(Action.QueryStart);

        const request: Observable<any> = this.http.request(new Request(requestOptions))
          .catch((err: any) => {
            const error = err.json();
            if (silent) {
              return Observable.throw(error);
            }

            switch (error.status) {
              case 409:
                return Observable.throw(error);
              case 401:
              case 403:
                this.store.dispatch({type: LOGOUT});
                return Observable.throw('User is not authenticated');
              default:
                console.error('Error', error);
                this.error.next(error);
                return Observable.throw(error);
            }
          }).finally(() => this.process.next(Action.QueryStop));

        return request.map((res: Response) => {
          if (res.text()) {
            try {
              return res.json();
            } catch (err) {
              return res.text();
            }
          }
        });
      });
  }