all files / src/ authHttpFetcher.js

90.91% Statements 20/22
75% Branches 6/8
100% Functions 5/5
95.24% Lines 20/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                       
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var httpFetcher_1 = require("./httpFetcher");
require("isomorphic-fetch");
var AuthHttpFetcher = (function () {
    function AuthHttpFetcher(uri, authToken) {
        var _this = this;
        this.myFetch = function (input, init) {
            Iif (init === void 0) { init = {}; }
            init.body = init.body || {};
            init.body.headers = init.body.headers || {};
            init.body.headers['authorization'] = _this.authToken();
            return fetch(input, init)
                .then(function (response) {
                Iif (response.status === 401) {
                    return new Response({
                        ok: false,
                    });
                }
                return response;
            });
        };
        this.httpFetcher = new httpFetcher_1.default({ uri: uri, fetch: this.myFetch });
        this.authToken = authToken;
    }
    AuthHttpFetcher.prototype.request = function (operation) {
        return this.httpFetcher.request(operation);
    };
    return AuthHttpFetcher;
}());
exports.default = AuthHttpFetcher;
//# sourceMappingURL=authHttpFetcher.js.map