@tramvai/tinkoff-request-http-client-adapter 0.9.175 → 0.9.178

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ const createAgent = () => { };
2
+
3
+ export { createAgent };
@@ -0,0 +1,14 @@
1
+ import http from 'http';
2
+ import https from 'https';
3
+
4
+ const createAgent = (options = {
5
+ keepAlive: true,
6
+ scheduling: 'lifo',
7
+ }) => {
8
+ return {
9
+ http: new http.Agent(options),
10
+ https: new https.Agent(options),
11
+ };
12
+ };
13
+
14
+ export { createAgent };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var http = require('http');
6
+ var https = require('https');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
11
+ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
12
+
13
+ const createAgent = (options = {
14
+ keepAlive: true,
15
+ scheduling: 'lifo',
16
+ }) => {
17
+ return {
18
+ http: new http__default["default"].Agent(options),
19
+ https: new https__default["default"].Agent(options),
20
+ };
21
+ };
22
+
23
+ exports.createAgent = createAgent;
@@ -0,0 +1,10 @@
1
+ import { createTinkoffRequest } from './createTinkoffRequest.browser.js';
2
+ import { HttpClientAdapter } from './httpClientAdapter.browser.js';
3
+
4
+ function createAdapter(options) {
5
+ const makeRequest = createTinkoffRequest(options);
6
+ const httpClientAdapter = new HttpClientAdapter({ options, makeRequest });
7
+ return httpClientAdapter;
8
+ }
9
+
10
+ export { createAdapter };
@@ -0,0 +1,10 @@
1
+ import { createTinkoffRequest } from './createTinkoffRequest.es.js';
2
+ import { HttpClientAdapter } from './httpClientAdapter.es.js';
3
+
4
+ function createAdapter(options) {
5
+ const makeRequest = createTinkoffRequest(options);
6
+ const httpClientAdapter = new HttpClientAdapter({ options, makeRequest });
7
+ return httpClientAdapter;
8
+ }
9
+
10
+ export { createAdapter };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var createTinkoffRequest = require('./createTinkoffRequest.js');
6
+ var httpClientAdapter = require('./httpClientAdapter.js');
7
+
8
+ function createAdapter(options) {
9
+ const makeRequest = createTinkoffRequest.createTinkoffRequest(options);
10
+ const httpClientAdapter$1 = new httpClientAdapter.HttpClientAdapter({ options, makeRequest });
11
+ return httpClientAdapter$1;
12
+ }
13
+
14
+ exports.createAdapter = createAdapter;
@@ -0,0 +1,108 @@
1
+ import either from '@tinkoff/utils/function/either';
2
+ import request from '@tinkoff/request-core';
3
+ import logPlugin from '@tinkoff/request-plugin-log';
4
+ import deduplicateCache from '@tinkoff/request-plugin-cache-deduplicate';
5
+ import memoryCache from '@tinkoff/request-plugin-cache-memory';
6
+ import validate from '@tinkoff/request-plugin-validate';
7
+ import http, { isServerError, isNetworkFail } from '@tinkoff/request-plugin-protocol-http';
8
+ import transformUrl from '@tinkoff/request-plugin-transform-url';
9
+ import circuitBreaker from '@tinkoff/request-plugin-circuit-breaker';
10
+ import retry from '@tinkoff/request-plugin-retry';
11
+ import { createAgent } from './agent/createAgent.browser.browser.js';
12
+
13
+ const defaultAgent = createAgent();
14
+ function createTinkoffRequest(options) {
15
+ const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, agent, querySerializer, retryOptions, ...defaults } = options;
16
+ const log = logger && logger(`${name}:initialization`);
17
+ const plugins = [];
18
+ plugins.push({
19
+ init: (context, next) => {
20
+ next({
21
+ request: {
22
+ timeout: defaultTimeout,
23
+ ...context.getRequest(),
24
+ },
25
+ });
26
+ },
27
+ });
28
+ plugins.push(transformUrl({
29
+ baseUrl: defaults.baseUrl,
30
+ transform: ({ baseUrl, path, url }) => {
31
+ // если пользователь передал `url`, не модифицируем его, ожидается что это абсолютный URI
32
+ if (url) {
33
+ if (process.env.NODE_ENV === 'development') {
34
+ if (url.indexOf('http') !== 0 && url.indexOf('//') !== 0) {
35
+ log === null || log === void 0 ? void 0 : log.error(`url запроса должен содержать протокол и хост! текущее значение: ${url}`);
36
+ }
37
+ }
38
+ return url;
39
+ }
40
+ if (baseUrl && path) {
41
+ const baseUrlHasTrailSlash = baseUrl.slice(-1) === '/';
42
+ const pathHasLeadSlash = path.slice(0, 1) === '/';
43
+ const needSlash = !baseUrlHasTrailSlash;
44
+ if (pathHasLeadSlash) {
45
+ // eslint-disable-next-line no-param-reassign
46
+ path = path.substring(1);
47
+ }
48
+ return `${baseUrl}${needSlash ? '/' : ''}${path}`;
49
+ }
50
+ if (process.env.NODE_ENV === 'development') {
51
+ if (!baseUrl && !path) {
52
+ log === null || log === void 0 ? void 0 : log.error(`запрос должен содержать url, или baseUrl с полным путем запроса, или baseUrl вместе с path!`);
53
+ }
54
+ }
55
+ return baseUrl || path || '';
56
+ },
57
+ }));
58
+ plugins.push(logPlugin({
59
+ logger,
60
+ name,
61
+ showQueryFields: true,
62
+ showPayloadFields: true,
63
+ }));
64
+ plugins.push(memoryCache({
65
+ shouldExecute: !disableCache,
66
+ lruOptions,
67
+ allowStale: true,
68
+ getCacheKey,
69
+ memoryConstructor: createCache,
70
+ }));
71
+ plugins.push(deduplicateCache(getCacheKey ? { getCacheKey } : undefined));
72
+ if (enableCircuitBreaker) {
73
+ plugins.push(circuitBreaker({
74
+ isSystemError: either(isServerError, isNetworkFail),
75
+ ...circuitBreakerOptions,
76
+ }));
77
+ }
78
+ plugins.push({
79
+ error: (context, next) => {
80
+ const state = context.getState();
81
+ const error = errorModificator === null || errorModificator === void 0 ? void 0 : errorModificator(state);
82
+ if (error) {
83
+ return next({
84
+ error,
85
+ });
86
+ }
87
+ return next();
88
+ },
89
+ });
90
+ if (validator || errorValidator) {
91
+ plugins.push(validate({
92
+ validator,
93
+ errorValidator,
94
+ allowFallback: true,
95
+ }));
96
+ }
97
+ plugins.push(http({
98
+ agent: agent || defaultAgent,
99
+ querySerializer: querySerializer || undefined,
100
+ }));
101
+ if (retryOptions) {
102
+ plugins.push(retry(retryOptions));
103
+ }
104
+ const makeRequest = request(plugins);
105
+ return makeRequest;
106
+ }
107
+
108
+ export { createTinkoffRequest };
@@ -0,0 +1,108 @@
1
+ import either from '@tinkoff/utils/function/either';
2
+ import request from '@tinkoff/request-core';
3
+ import logPlugin from '@tinkoff/request-plugin-log';
4
+ import deduplicateCache from '@tinkoff/request-plugin-cache-deduplicate';
5
+ import memoryCache from '@tinkoff/request-plugin-cache-memory';
6
+ import validate from '@tinkoff/request-plugin-validate';
7
+ import http, { isServerError, isNetworkFail } from '@tinkoff/request-plugin-protocol-http';
8
+ import transformUrl from '@tinkoff/request-plugin-transform-url';
9
+ import circuitBreaker from '@tinkoff/request-plugin-circuit-breaker';
10
+ import retry from '@tinkoff/request-plugin-retry';
11
+ import { createAgent } from './agent/createAgent.es.js';
12
+
13
+ const defaultAgent = createAgent();
14
+ function createTinkoffRequest(options) {
15
+ const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, agent, querySerializer, retryOptions, ...defaults } = options;
16
+ const log = logger && logger(`${name}:initialization`);
17
+ const plugins = [];
18
+ plugins.push({
19
+ init: (context, next) => {
20
+ next({
21
+ request: {
22
+ timeout: defaultTimeout,
23
+ ...context.getRequest(),
24
+ },
25
+ });
26
+ },
27
+ });
28
+ plugins.push(transformUrl({
29
+ baseUrl: defaults.baseUrl,
30
+ transform: ({ baseUrl, path, url }) => {
31
+ // если пользователь передал `url`, не модифицируем его, ожидается что это абсолютный URI
32
+ if (url) {
33
+ if (process.env.NODE_ENV === 'development') {
34
+ if (url.indexOf('http') !== 0 && url.indexOf('//') !== 0) {
35
+ log === null || log === void 0 ? void 0 : log.error(`url запроса должен содержать протокол и хост! текущее значение: ${url}`);
36
+ }
37
+ }
38
+ return url;
39
+ }
40
+ if (baseUrl && path) {
41
+ const baseUrlHasTrailSlash = baseUrl.slice(-1) === '/';
42
+ const pathHasLeadSlash = path.slice(0, 1) === '/';
43
+ const needSlash = !baseUrlHasTrailSlash;
44
+ if (pathHasLeadSlash) {
45
+ // eslint-disable-next-line no-param-reassign
46
+ path = path.substring(1);
47
+ }
48
+ return `${baseUrl}${needSlash ? '/' : ''}${path}`;
49
+ }
50
+ if (process.env.NODE_ENV === 'development') {
51
+ if (!baseUrl && !path) {
52
+ log === null || log === void 0 ? void 0 : log.error(`запрос должен содержать url, или baseUrl с полным путем запроса, или baseUrl вместе с path!`);
53
+ }
54
+ }
55
+ return baseUrl || path || '';
56
+ },
57
+ }));
58
+ plugins.push(logPlugin({
59
+ logger,
60
+ name,
61
+ showQueryFields: true,
62
+ showPayloadFields: true,
63
+ }));
64
+ plugins.push(memoryCache({
65
+ shouldExecute: !disableCache,
66
+ lruOptions,
67
+ allowStale: true,
68
+ getCacheKey,
69
+ memoryConstructor: createCache,
70
+ }));
71
+ plugins.push(deduplicateCache(getCacheKey ? { getCacheKey } : undefined));
72
+ if (enableCircuitBreaker) {
73
+ plugins.push(circuitBreaker({
74
+ isSystemError: either(isServerError, isNetworkFail),
75
+ ...circuitBreakerOptions,
76
+ }));
77
+ }
78
+ plugins.push({
79
+ error: (context, next) => {
80
+ const state = context.getState();
81
+ const error = errorModificator === null || errorModificator === void 0 ? void 0 : errorModificator(state);
82
+ if (error) {
83
+ return next({
84
+ error,
85
+ });
86
+ }
87
+ return next();
88
+ },
89
+ });
90
+ if (validator || errorValidator) {
91
+ plugins.push(validate({
92
+ validator,
93
+ errorValidator,
94
+ allowFallback: true,
95
+ }));
96
+ }
97
+ plugins.push(http({
98
+ agent: agent || defaultAgent,
99
+ querySerializer: querySerializer || undefined,
100
+ }));
101
+ if (retryOptions) {
102
+ plugins.push(retry(retryOptions));
103
+ }
104
+ const makeRequest = request(plugins);
105
+ return makeRequest;
106
+ }
107
+
108
+ export { createTinkoffRequest };
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var either = require('@tinkoff/utils/function/either');
6
+ var request = require('@tinkoff/request-core');
7
+ var logPlugin = require('@tinkoff/request-plugin-log');
8
+ var deduplicateCache = require('@tinkoff/request-plugin-cache-deduplicate');
9
+ var memoryCache = require('@tinkoff/request-plugin-cache-memory');
10
+ var validate = require('@tinkoff/request-plugin-validate');
11
+ var http = require('@tinkoff/request-plugin-protocol-http');
12
+ var transformUrl = require('@tinkoff/request-plugin-transform-url');
13
+ var circuitBreaker = require('@tinkoff/request-plugin-circuit-breaker');
14
+ var retry = require('@tinkoff/request-plugin-retry');
15
+ var createAgent = require('./agent/createAgent.js');
16
+
17
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
+
19
+ var either__default = /*#__PURE__*/_interopDefaultLegacy(either);
20
+ var request__default = /*#__PURE__*/_interopDefaultLegacy(request);
21
+ var logPlugin__default = /*#__PURE__*/_interopDefaultLegacy(logPlugin);
22
+ var deduplicateCache__default = /*#__PURE__*/_interopDefaultLegacy(deduplicateCache);
23
+ var memoryCache__default = /*#__PURE__*/_interopDefaultLegacy(memoryCache);
24
+ var validate__default = /*#__PURE__*/_interopDefaultLegacy(validate);
25
+ var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
26
+ var transformUrl__default = /*#__PURE__*/_interopDefaultLegacy(transformUrl);
27
+ var circuitBreaker__default = /*#__PURE__*/_interopDefaultLegacy(circuitBreaker);
28
+ var retry__default = /*#__PURE__*/_interopDefaultLegacy(retry);
29
+
30
+ const defaultAgent = createAgent.createAgent();
31
+ function createTinkoffRequest(options) {
32
+ const { logger, name, disableCache, enableCircuitBreaker, createCache, cacheTime = 30000, defaultTimeout, validator, errorValidator, errorModificator, circuitBreakerOptions = {}, getCacheKey, lruOptions = { max: 1000, maxAge: cacheTime }, agent, querySerializer, retryOptions, ...defaults } = options;
33
+ const log = logger && logger(`${name}:initialization`);
34
+ const plugins = [];
35
+ plugins.push({
36
+ init: (context, next) => {
37
+ next({
38
+ request: {
39
+ timeout: defaultTimeout,
40
+ ...context.getRequest(),
41
+ },
42
+ });
43
+ },
44
+ });
45
+ plugins.push(transformUrl__default["default"]({
46
+ baseUrl: defaults.baseUrl,
47
+ transform: ({ baseUrl, path, url }) => {
48
+ // если пользователь передал `url`, не модифицируем его, ожидается что это абсолютный URI
49
+ if (url) {
50
+ if (process.env.NODE_ENV === 'development') {
51
+ if (url.indexOf('http') !== 0 && url.indexOf('//') !== 0) {
52
+ log === null || log === void 0 ? void 0 : log.error(`url запроса должен содержать протокол и хост! текущее значение: ${url}`);
53
+ }
54
+ }
55
+ return url;
56
+ }
57
+ if (baseUrl && path) {
58
+ const baseUrlHasTrailSlash = baseUrl.slice(-1) === '/';
59
+ const pathHasLeadSlash = path.slice(0, 1) === '/';
60
+ const needSlash = !baseUrlHasTrailSlash;
61
+ if (pathHasLeadSlash) {
62
+ // eslint-disable-next-line no-param-reassign
63
+ path = path.substring(1);
64
+ }
65
+ return `${baseUrl}${needSlash ? '/' : ''}${path}`;
66
+ }
67
+ if (process.env.NODE_ENV === 'development') {
68
+ if (!baseUrl && !path) {
69
+ log === null || log === void 0 ? void 0 : log.error(`запрос должен содержать url, или baseUrl с полным путем запроса, или baseUrl вместе с path!`);
70
+ }
71
+ }
72
+ return baseUrl || path || '';
73
+ },
74
+ }));
75
+ plugins.push(logPlugin__default["default"]({
76
+ logger,
77
+ name,
78
+ showQueryFields: true,
79
+ showPayloadFields: true,
80
+ }));
81
+ plugins.push(memoryCache__default["default"]({
82
+ shouldExecute: !disableCache,
83
+ lruOptions,
84
+ allowStale: true,
85
+ getCacheKey,
86
+ memoryConstructor: createCache,
87
+ }));
88
+ plugins.push(deduplicateCache__default["default"](getCacheKey ? { getCacheKey } : undefined));
89
+ if (enableCircuitBreaker) {
90
+ plugins.push(circuitBreaker__default["default"]({
91
+ isSystemError: either__default["default"](http.isServerError, http.isNetworkFail),
92
+ ...circuitBreakerOptions,
93
+ }));
94
+ }
95
+ plugins.push({
96
+ error: (context, next) => {
97
+ const state = context.getState();
98
+ const error = errorModificator === null || errorModificator === void 0 ? void 0 : errorModificator(state);
99
+ if (error) {
100
+ return next({
101
+ error,
102
+ });
103
+ }
104
+ return next();
105
+ },
106
+ });
107
+ if (validator || errorValidator) {
108
+ plugins.push(validate__default["default"]({
109
+ validator,
110
+ errorValidator,
111
+ allowFallback: true,
112
+ }));
113
+ }
114
+ plugins.push(http__default["default"]({
115
+ agent: agent || defaultAgent,
116
+ querySerializer: querySerializer || undefined,
117
+ }));
118
+ if (retryOptions) {
119
+ plugins.push(retry__default["default"](retryOptions));
120
+ }
121
+ const makeRequest = request__default["default"](plugins);
122
+ return makeRequest;
123
+ }
124
+
125
+ exports.createTinkoffRequest = createTinkoffRequest;
@@ -0,0 +1,60 @@
1
+ import { getStatus, getHeaders } from '@tinkoff/request-plugin-protocol-http';
2
+ import { BaseHttpClient } from '@tramvai/http-client';
3
+ import { mergeOptions } from './mergeOptions.browser.js';
4
+
5
+ class HttpClientAdapter extends BaseHttpClient {
6
+ constructor({ options, makeRequest, }) {
7
+ super();
8
+ this.options = options;
9
+ this.makeRequest = makeRequest;
10
+ }
11
+ async request(req) {
12
+ // применяем дефолтные опции до вызова modifyRequest на объекте запроса
13
+ const optionsWithDefaults = mergeOptions(this.options, req);
14
+ const { modifyRequest, modifyResponse, modifyError, ...reqWithDefaults } = optionsWithDefaults;
15
+ const { method, body, requestType, ...adaptedReq } = modifyRequest
16
+ ? modifyRequest(reqWithDefaults)
17
+ : reqWithDefaults;
18
+ if (method) {
19
+ adaptedReq.httpMethod = method;
20
+ }
21
+ if (body) {
22
+ adaptedReq.payload = body;
23
+ }
24
+ if (requestType) {
25
+ adaptedReq.type = requestType;
26
+ }
27
+ const res = this.makeRequest(adaptedReq);
28
+ try {
29
+ const payload = await res;
30
+ const status = getStatus(res);
31
+ const headers = getHeaders(res);
32
+ const resToModify = {
33
+ payload,
34
+ status,
35
+ headers,
36
+ };
37
+ return modifyResponse ? modifyResponse(resToModify) : resToModify;
38
+ }
39
+ catch (error) {
40
+ const meta = res.getExternalMeta();
41
+ const status = getStatus(res);
42
+ const headers = getHeaders(res);
43
+ // Useful for logging
44
+ const errorWithMeta = Object.assign(error, {
45
+ __meta: meta,
46
+ status,
47
+ headers,
48
+ });
49
+ throw modifyError ? modifyError(errorWithMeta, adaptedReq) : errorWithMeta;
50
+ }
51
+ }
52
+ fork(forkOptions = {}, mergeOptionsConfig = {}) {
53
+ return new HttpClientAdapter({
54
+ options: mergeOptions(this.options, forkOptions, mergeOptionsConfig),
55
+ makeRequest: this.makeRequest,
56
+ });
57
+ }
58
+ }
59
+
60
+ export { HttpClientAdapter };
@@ -0,0 +1,60 @@
1
+ import { getStatus, getHeaders } from '@tinkoff/request-plugin-protocol-http';
2
+ import { BaseHttpClient } from '@tramvai/http-client';
3
+ import { mergeOptions } from './mergeOptions.es.js';
4
+
5
+ class HttpClientAdapter extends BaseHttpClient {
6
+ constructor({ options, makeRequest, }) {
7
+ super();
8
+ this.options = options;
9
+ this.makeRequest = makeRequest;
10
+ }
11
+ async request(req) {
12
+ // применяем дефолтные опции до вызова modifyRequest на объекте запроса
13
+ const optionsWithDefaults = mergeOptions(this.options, req);
14
+ const { modifyRequest, modifyResponse, modifyError, ...reqWithDefaults } = optionsWithDefaults;
15
+ const { method, body, requestType, ...adaptedReq } = modifyRequest
16
+ ? modifyRequest(reqWithDefaults)
17
+ : reqWithDefaults;
18
+ if (method) {
19
+ adaptedReq.httpMethod = method;
20
+ }
21
+ if (body) {
22
+ adaptedReq.payload = body;
23
+ }
24
+ if (requestType) {
25
+ adaptedReq.type = requestType;
26
+ }
27
+ const res = this.makeRequest(adaptedReq);
28
+ try {
29
+ const payload = await res;
30
+ const status = getStatus(res);
31
+ const headers = getHeaders(res);
32
+ const resToModify = {
33
+ payload,
34
+ status,
35
+ headers,
36
+ };
37
+ return modifyResponse ? modifyResponse(resToModify) : resToModify;
38
+ }
39
+ catch (error) {
40
+ const meta = res.getExternalMeta();
41
+ const status = getStatus(res);
42
+ const headers = getHeaders(res);
43
+ // Useful for logging
44
+ const errorWithMeta = Object.assign(error, {
45
+ __meta: meta,
46
+ status,
47
+ headers,
48
+ });
49
+ throw modifyError ? modifyError(errorWithMeta, adaptedReq) : errorWithMeta;
50
+ }
51
+ }
52
+ fork(forkOptions = {}, mergeOptionsConfig = {}) {
53
+ return new HttpClientAdapter({
54
+ options: mergeOptions(this.options, forkOptions, mergeOptionsConfig),
55
+ makeRequest: this.makeRequest,
56
+ });
57
+ }
58
+ }
59
+
60
+ export { HttpClientAdapter };
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var http = require('@tinkoff/request-plugin-protocol-http');
6
+ var httpClient = require('@tramvai/http-client');
7
+ var mergeOptions = require('./mergeOptions.js');
8
+
9
+ class HttpClientAdapter extends httpClient.BaseHttpClient {
10
+ constructor({ options, makeRequest, }) {
11
+ super();
12
+ this.options = options;
13
+ this.makeRequest = makeRequest;
14
+ }
15
+ async request(req) {
16
+ // применяем дефолтные опции до вызова modifyRequest на объекте запроса
17
+ const optionsWithDefaults = mergeOptions.mergeOptions(this.options, req);
18
+ const { modifyRequest, modifyResponse, modifyError, ...reqWithDefaults } = optionsWithDefaults;
19
+ const { method, body, requestType, ...adaptedReq } = modifyRequest
20
+ ? modifyRequest(reqWithDefaults)
21
+ : reqWithDefaults;
22
+ if (method) {
23
+ adaptedReq.httpMethod = method;
24
+ }
25
+ if (body) {
26
+ adaptedReq.payload = body;
27
+ }
28
+ if (requestType) {
29
+ adaptedReq.type = requestType;
30
+ }
31
+ const res = this.makeRequest(adaptedReq);
32
+ try {
33
+ const payload = await res;
34
+ const status = http.getStatus(res);
35
+ const headers = http.getHeaders(res);
36
+ const resToModify = {
37
+ payload,
38
+ status,
39
+ headers,
40
+ };
41
+ return modifyResponse ? modifyResponse(resToModify) : resToModify;
42
+ }
43
+ catch (error) {
44
+ const meta = res.getExternalMeta();
45
+ const status = http.getStatus(res);
46
+ const headers = http.getHeaders(res);
47
+ // Useful for logging
48
+ const errorWithMeta = Object.assign(error, {
49
+ __meta: meta,
50
+ status,
51
+ headers,
52
+ });
53
+ throw modifyError ? modifyError(errorWithMeta, adaptedReq) : errorWithMeta;
54
+ }
55
+ }
56
+ fork(forkOptions = {}, mergeOptionsConfig = {}) {
57
+ return new HttpClientAdapter({
58
+ options: mergeOptions.mergeOptions(this.options, forkOptions, mergeOptionsConfig),
59
+ makeRequest: this.makeRequest,
60
+ });
61
+ }
62
+ }
63
+
64
+ exports.HttpClientAdapter = HttpClientAdapter;