Observable_1.Observable.throw не является функцией с adal-angular8 - PullRequest
0 голосов
/ 17 февраля 2020

ошибка: Ошибка типа: Observable_1.Observable.throw не является функцией в CatchSubscriber.pu sh .. / node_modules / adal-angular8 / adal8-http.service. js .Adal8HTTPService.handleError [as селектор] (adal8-http.service. js: 172) на CatchSubscriber.pu sh .. / node_modules / rxjs / _esm5 / internal / operator / catchError. js .CatchSubscriber.error (catchError. js : 34) в MapSubscriber.pu sh .. / node_modules / rxjs / _esm5 / internal / Subscriber. js .Subscriber._error (Подписчик. js: 79) в MapSubscriber.pu sh .. / node_modules /rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Подписчик. js: 59) в FilterSubscriber.pu sh .. / node_modules / rxjs / _esm5 / internal / Subscriber. js .Subscriber ._error (Subscriber. js: 79) в FilterSubscriber.pu sh .. / node_modules / rxjs / _esm5 / internal / Subscriber. js .Subscriber.error (Subscriber. js: 59) в MergeMapSubscriber. pu sh .. / node_modules / rxjs / _esm5 / internal / OuterSubscriber. js .OuterSubscriber.notifyError (OuterSubscriber. js: 13 ) в InnerSubscriber.pu sh .. / node_modules / rxjs / _esm5 / internal / InnerSubscriber. js .InnerSubscriber._error (InnerSubscriber. js: 18) в InnerSubscriber.pu sh .. / nodejmodules /_esm5/internal/Subscriber.js.Subscriber.error (подписчик. js: 59) в XMLHttpRequest.onLoad (http. js: 1707)

Я получаю это ошибка каждый раз, когда мой API возвращает ошибку 400

, вы найдете под моим фрагментом кода:

    import { Injectable } from '@angular/core';
    import { Adal8HTTPService } from 'adal-angular8';
    import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
    import { Observable,throwError  } from 'rxjs';
    import { catchError } from "rxjs/operators";
    @Injectable({
      providedIn: 'root'
    })

    export class HttpService {
      constructor(
        private adal8HttpService: Adal8HTTPService
      ) { }

      public post(url: string, body: any): Observable<any> {
        const options = this.prepareOptions();
        return this.adal8HttpService.post(url, body, options).pipe(
          catchError(this.handleError)
        )
      }
      private prepareOptions(): any {
        let headers = new HttpHeaders();
        return {headers};
      }

      handleError(err: HttpErrorResponse) {
        console.log('err', err) <== error is displayed here
        return throwError(err);
      }
    }

дополнительная служба в фрагменте кода модуля узла:

    "use strict";
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    Object.defineProperty(exports, "__esModule", { value: true });
    var Observable_1 = require("rxjs/internal/Observable");
    var core_1 = require("@angular/core");
    var http_1 = require("@angular/common/http");
    var operators_1 = require("rxjs/operators");
    /**
     *
     *
     * @export
     * @class Adal8HTTPService
     */
    var Adal8HTTPService = /** @class */ (function () {
        /**
         * Creates an instance of Adal8HTTPService.
         * @param {HttpClient} http
         * @param {Adal8Service} service
         *
         * @memberOf Adal8HTTPService
         */
        function Adal8HTTPService(http, service) {
            this.http = http;
            this.service = service;
        }
        Adal8HTTPService_1 = Adal8HTTPService;
        /**
         *
         *
         * @static
         * @param {HttpClient} http
         * @param {Adal8Service} service
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.factory = function (http, service) {
            return new Adal8HTTPService_1(http, service);
        };
        /**
         *
         *
         * @param {string} url
         * @param {*} [options]
         * @returns {Observable<any>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.get = function (url, options) {
            return this.sendRequest('get', url, options);
        };
        /**
         *
         *
         * @param {string} url
         * @param {*} body
         * @param {*} [options]
         * @returns {Observable<any>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.post = function (url, body, options) {
            options.body = body;
            return this.sendRequest('post', url, options);
        };
        /**
         *
         *
         * @param {string} url
         * @param {*} [options]
         * @returns {Observable<any>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.delete = function (url, options) {
            return this.sendRequest('delete', url, options);
        };
        /**
         *
         *
         * @param {string} url
         * @param {*} body
         * @param {*} [options]
         * @returns {Observable<any>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.patch = function (url, body, options) {
            options.body = body;
            return this.sendRequest('patch', url, options);
        };
        /**
         *
         *
         * @param {string} url
         * @param {*} body
         * @param {*} [options]
         * @returns {Observable<any>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.put = function (url, body, options) {
            options.body = body;
            return this.sendRequest('put', url, options);
        };
        /**
         *
         *
         * @param {string} url
         * @param {*} [options]
         * @returns {Observable<any>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.head = function (url, options) {
            return this.sendRequest('head', url, options);
        };
        /**
         *
         *
         * @private
         * @param {string} method
         * @param {string} url
         * @param {RequestOptionsArgs} options
         * @returns {Observable<string>}
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.sendRequest = function (method, url, options) {
            var _this = this;
            var resource = this.service.getResourceForEndpoint(url);
            var authenticatedCall;
            if (resource) {
                if (this.service.userInfo.authenticated) {
                    authenticatedCall = this.service.acquireToken(resource)
                        .pipe(operators_1.mergeMap(function (token) {
                        if (options.headers == null) {
                            options.headers = new http_1.HttpHeaders();
                        }
                        options.headers = options.headers.append('Authorization', 'Bearer ' + token);
                        return _this.http.request(method, url, options)
                            .pipe(operators_1.catchError(_this.handleError));
                    }));
                }
                else {
                    authenticatedCall = Observable_1.Observable.throw(new Error('User Not Authenticated.'));
                }
            }
            else {
                authenticatedCall = this.http.request(method, url, options)
                    .pipe(operators_1.catchError(this.handleError));
            }
            return authenticatedCall;
        };
        /**
         *
         *
         * @private
         * @param {*} error
         * @returns
         *
         * @memberOf Adal8HTTPService
         */
        Adal8HTTPService.prototype.handleError = function (error) {
            // In a real world app, we might send the error to remote logging infrastructure
            var errMsg = error.message || 'Server error';
            console.error(JSON.stringify(error)); // log to console instead
            return Observable_1.Observable.throw(error); <== this line cause the probleme
        };
        var Adal8HTTPService_1;
        Adal8HTTPService = Adal8HTTPService_1 = __decorate([
            core_1.Injectable()
        ], Adal8HTTPService);
        return Adal8HTTPService;
    }());
    exports.Adal8HTTPService = Adal8HTTPService;
...