"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var axios_1 = require("axios");
var promise_1 = require("promise");
var routes_1 = require("../apiClient/routes");
var localStorageService_1 = require("./localStorageService");
// set default URL for axios
/*axios.defaults.baseURL = config.server.apiUrl;*/
axios_1.default.defaults.baseURL = process.env.REACT_APP_API_URL;
// dunno
axios_1.default.interceptors.response.use(undefined, function (error) {
    var expectedError = error.response && error.response.status && error.response.status >= 400 && error.response.status < 500;
    if (!expectedError) {
        console.log("Logging the error", error);
        alert("Došlo k neočekávané chybě.");
    }
    return (0, promise_1.reject)(error);
});
function setAuthorizationToken(authorizationToken) {
    if (authorizationToken !== null) {
        axios_1.default.defaults.headers.common['Authorization'] = "Bearer ".concat(authorizationToken);
    }
    else {
        delete axios_1.default.defaults.headers.common["Authorization"];
    }
}
function refreshToken() {
    if ((0, localStorageService_1.IsJwtForRefresh)()) {
        axios_1.default.get(routes_1.AccountController_RefreshJwtToken).then(function (response) { return (0, localStorageService_1.SetAuthorizationTokenLocalStorage)(response.data); });
    }
}
exports.default = {
    get: axios_1.default.get,
    post: axios_1.default.post,
    put: axios_1.default.put,
    delete: axios_1.default.delete,
    all: axios_1.default.all,
    spread: axios_1.default.spread,
    setAuthorizationToken: setAuthorizationToken,
    refreshToken: refreshToken
};
//# sourceMappingURL=httpService.js.map