axios-light-my-request-adapter
Version:
Axios adapter for Light my Request
40 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.settle = exports.buildFullPath = void 0;
const axios_1 = require("axios");
const axios_helpers_1 = require("./axios-helpers");
/**
* Creates a new URL by combining the baseURL with the requestedURL,
* only when the requestedURL is not already an absolute URL.
* If the requestURL is absolute, this function returns the requestedURL untouched.
*
* @param {string} baseURL The base URL
* @param {string} requestedURL Absolute or relative URL to combine
* @returns {string} The combined full path
*/
function buildFullPath(baseURL, requestedURL) {
if (baseURL && !(0, axios_helpers_1.isAbsoluteURL)(requestedURL)) {
return (0, axios_helpers_1.combineURLs)(baseURL, requestedURL);
}
return requestedURL;
}
exports.buildFullPath = buildFullPath;
/**
* Resolve or reject a Promise based on response status.
*
* @param {Function} resolve A function that resolves the promise.
* @param {Function} reject A function that rejects the promise.
* @param {object} response The response.
*/
function settle(resolve, reject, response) {
const validateStatus = response.config.validateStatus;
if (!response.status || !validateStatus || validateStatus(response.status)) {
Promise;
resolve(response);
}
else {
reject(new axios_1.AxiosError(`Request failed with status code ${response.status}`, [axios_1.AxiosError.ERR_BAD_REQUEST, axios_1.AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response));
}
}
exports.settle = settle;
//# sourceMappingURL=axios-core.js.map