private makeApiCall()

in lib/paris.ts [296:349]


	private makeApiCall<TResult, TParams = UrlParams, TData = any, TRawDataResult = TResult>(backendConfig:ApiCallBackendConfigInterface<TResult, TRawDataResult>, method:RequestMethod, httpOptions:Readonly<HttpOptions<TData, TParams>>, query?: DataQuery, requestOptions?: AjaxRequest):Observable<TResult>{
		const dataQuery: DataQuery = query || { where: httpOptions && httpOptions.params };
		let endpoint:string;
		if (backendConfig.endpoint instanceof Function)
			endpoint = backendConfig.endpoint(this.config, dataQuery);
		else if (backendConfig.endpoint)
			endpoint = backendConfig.endpoint;
		else
			throw new Error(`Can't call API, no endpoint specified.`);

		const baseUrl:string = backendConfig.baseUrl instanceof Function ? backendConfig.baseUrl(this.config, dataQuery) : backendConfig.baseUrl;
		let apiCallHttpOptions:HttpOptions<TData> = clone(httpOptions) || {};

		if (backendConfig.separateArrayParams) {
			apiCallHttpOptions.separateArrayParams = true;
		}

		if (backendConfig.fixedData){
			if (!apiCallHttpOptions.params)
				apiCallHttpOptions.params = <TParams>{};

			Object.assign(apiCallHttpOptions.params, backendConfig.fixedData);
		}

		const self = this;
		function makeRequest$<T>(): Observable<T> {
			return self.dataStore.request<T>(method || "GET", endpoint, apiCallHttpOptions, baseUrl, requestOptions).pipe(
				catchError(err => {
					return throwError({
						originalError: err,
						type: EntityErrorTypes.HttpError,
						entity: null
					})
				}))
		}

		if (backendConfig.parseData) {
			return makeRequest$<TRawDataResult>().pipe(
				map((rawData: TRawDataResult) => {
					try {
						return backendConfig.parseData(rawData, this.config, dataQuery)
					} catch (err) {
						throw {
							originalError: err,
							type: EntityErrorTypes.DataParseError,
							entity: null
						}
					}
				}),
			);
		}

		return makeRequest$<TResult>()
	}