@taquito/http-utils 11.1.0 → 12.0.0-beta-RC.0
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.
- package/README.md +34 -7
- package/dist/lib/taquito-http-utils.js +69 -72
- package/dist/lib/taquito-http-utils.js.map +1 -1
- package/dist/lib/version.js +2 -4
- package/dist/lib/version.js.map +1 -1
- package/dist/{taquito-http-utils.es5.js → taquito-http-utils.es6.js} +91 -79
- package/dist/{taquito-http-utils.es5.js.map → taquito-http-utils.es6.js.map} +1 -1
- package/dist/taquito-http-utils.umd.js +475 -461
- package/dist/taquito-http-utils.umd.js.map +1 -1
- package/dist/types/taquito-http-utils.d.ts +3 -5
- package/package.json +21 -21
package/README.md
CHANGED
|
@@ -1,20 +1,47 @@
|
|
|
1
1
|
# Taquito HTTP Utilities package
|
|
2
|
+
*TypeDoc style documentation is available [here](https://tezostaquito.io/typedoc/modules/_taquito_http_utils.html)*
|
|
2
3
|
|
|
3
|
-
`@taquito/http-utils` is an npm package that provides developers with http functionality for Taquito.
|
|
4
|
+
`@taquito/http-utils` is an npm package that provides developers with http functionality for Taquito.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## General Information
|
|
6
7
|
|
|
8
|
+
The `HttpBackend` class contains a `createRequest` method which accepts options to be passed for the HTTP request (url, method, timeout, json, query, headers, mimeType). This method will help users interact with the RPC with a more familiar HTTP format.
|
|
9
|
+
|
|
10
|
+
Parameters for `createRequest`:
|
|
11
|
+
|
|
12
|
+
`url`(string): RPC URL pointing to the Tezos node
|
|
13
|
+
`method`(string): HTTP method of the request
|
|
14
|
+
`timeout`(number): request timeout
|
|
15
|
+
`json`(boolean): Parse response into JSON when set to `true`; defaults to `true`
|
|
16
|
+
`query`(object): Query that we would like to pass as an HTTP request
|
|
17
|
+
`headers`(object): HTTP request header
|
|
18
|
+
`mimeType`(string): Sets the MIME type of the request; see [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
The package(s) need to be installed as follows
|
|
23
|
+
```
|
|
24
|
+
npm install @taquito/http-utils
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
Create an instance of `HttpBackend` and call it's member function `createRequest` to construct an HTTP request.
|
|
7
29
|
```ts
|
|
8
30
|
import { HttpBackend } from '@taquito/http-utils';
|
|
9
31
|
|
|
10
|
-
const
|
|
11
|
-
|
|
32
|
+
const httpBackend = new HttpBackend();
|
|
33
|
+
const response = httpBackend.createRequest<string>({
|
|
34
|
+
url: `/chains/${chain}/blocks/${block}/context/contracts/${address}/script`,
|
|
35
|
+
method: 'GET',
|
|
36
|
+
mimeType: "text; charset=utf-8",
|
|
37
|
+
json: false
|
|
38
|
+
});
|
|
12
39
|
|
|
13
|
-
|
|
40
|
+
```
|
|
14
41
|
|
|
15
|
-
##
|
|
42
|
+
## Additional Info
|
|
43
|
+
See the top-level https://github.com/ecadlabs/taquito file for details on reporting issues, contributing, and versioning.
|
|
16
44
|
|
|
17
|
-
TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_http_utils.html)
|
|
18
45
|
|
|
19
46
|
## Disclaimer
|
|
20
47
|
|
|
@@ -13,18 +13,30 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
16
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
26
|
exports.HttpBackend = exports.HttpRequestFailed = exports.HttpResponseError = exports.VERSION = void 0;
|
|
18
|
-
|
|
19
|
-
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
20
|
-
// tslint:enable: strict-type-predicates
|
|
21
|
-
var XMLHttpRequestCTOR = isNode ? require('xhr2-cookies').XMLHttpRequest : XMLHttpRequest;
|
|
27
|
+
const axios_1 = require("axios");
|
|
22
28
|
__exportStar(require("./status_code"), exports);
|
|
23
29
|
var version_1 = require("./version");
|
|
24
30
|
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
|
|
31
|
+
const defaultTimeout = 30000;
|
|
32
|
+
var ResponseType;
|
|
33
|
+
(function (ResponseType) {
|
|
34
|
+
ResponseType["TEXT"] = "text";
|
|
35
|
+
ResponseType["JSON"] = "json";
|
|
36
|
+
})(ResponseType || (ResponseType = {}));
|
|
37
|
+
class HttpResponseError extends Error {
|
|
38
|
+
constructor(message, status, statusText, body, url) {
|
|
39
|
+
super(message);
|
|
28
40
|
this.message = message;
|
|
29
41
|
this.status = status;
|
|
30
42
|
this.statusText = statusText;
|
|
@@ -32,115 +44,100 @@ var HttpResponseError = /** @class */ (function () {
|
|
|
32
44
|
this.url = url;
|
|
33
45
|
this.name = 'HttpResponse';
|
|
34
46
|
}
|
|
35
|
-
|
|
36
|
-
}());
|
|
47
|
+
}
|
|
37
48
|
exports.HttpResponseError = HttpResponseError;
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
class HttpRequestFailed extends Error {
|
|
50
|
+
constructor(url, innerEvent) {
|
|
51
|
+
super(`Request to ${url} failed`);
|
|
40
52
|
this.url = url;
|
|
41
53
|
this.innerEvent = innerEvent;
|
|
42
54
|
this.name = 'HttpRequestFailed';
|
|
43
|
-
this.message = "Request to " + url + " failed";
|
|
44
55
|
}
|
|
45
|
-
|
|
46
|
-
}());
|
|
56
|
+
}
|
|
47
57
|
exports.HttpRequestFailed = HttpRequestFailed;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
HttpBackend.prototype.serialize = function (obj) {
|
|
58
|
+
class HttpBackend {
|
|
59
|
+
serialize(obj) {
|
|
52
60
|
if (!obj) {
|
|
53
61
|
return '';
|
|
54
62
|
}
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
const str = [];
|
|
64
|
+
for (const p in obj) {
|
|
65
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
57
66
|
if (obj.hasOwnProperty(p) && typeof obj[p] !== 'undefined') {
|
|
58
|
-
|
|
67
|
+
const prop = typeof obj[p].toJSON === 'function' ? obj[p].toJSON() : obj[p];
|
|
59
68
|
// query arguments can have no value so we need some way of handling that
|
|
60
69
|
// example https://domain.com/query?all
|
|
61
70
|
if (prop === null) {
|
|
62
71
|
str.push(encodeURIComponent(p));
|
|
63
|
-
|
|
72
|
+
continue;
|
|
64
73
|
}
|
|
65
74
|
// another use case is multiple arguments with the same name
|
|
66
75
|
// they are passed as array
|
|
67
76
|
if (Array.isArray(prop)) {
|
|
68
|
-
prop.forEach(
|
|
77
|
+
prop.forEach((item) => {
|
|
69
78
|
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(item));
|
|
70
79
|
});
|
|
71
|
-
|
|
80
|
+
continue;
|
|
72
81
|
}
|
|
73
82
|
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(prop));
|
|
74
83
|
}
|
|
75
|
-
};
|
|
76
|
-
for (var p in obj) {
|
|
77
|
-
_loop_1(p);
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
const serialized = str.join('&');
|
|
80
86
|
if (serialized) {
|
|
81
|
-
return
|
|
87
|
+
return `?${serialized}`;
|
|
82
88
|
}
|
|
83
89
|
else {
|
|
84
90
|
return '';
|
|
85
91
|
}
|
|
86
|
-
}
|
|
87
|
-
HttpBackend.prototype.createXHR = function () {
|
|
88
|
-
return new XMLHttpRequestCTOR();
|
|
89
|
-
};
|
|
92
|
+
}
|
|
90
93
|
/**
|
|
91
94
|
*
|
|
92
95
|
* @param options contains options to be passed for the HTTP request (url, method and timeout)
|
|
93
96
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var request = _this.createXHR();
|
|
99
|
-
request.open(method || 'GET', "" + url + _this.serialize(query));
|
|
97
|
+
createRequest({ url, method, timeout = defaultTimeout, query, headers = {}, json = true }, data) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
let resType;
|
|
100
|
+
let transformResponse = undefined;
|
|
100
101
|
if (!headers['Content-Type']) {
|
|
101
|
-
|
|
102
|
+
headers['Content-Type'] = 'application/json';
|
|
103
|
+
}
|
|
104
|
+
if (!json) {
|
|
105
|
+
resType = ResponseType.TEXT;
|
|
106
|
+
transformResponse = [(v) => v];
|
|
102
107
|
}
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
else {
|
|
109
|
+
resType = ResponseType.JSON;
|
|
105
110
|
}
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
let response;
|
|
112
|
+
try {
|
|
113
|
+
response = yield axios_1.default.request({
|
|
114
|
+
url: url + this.serialize(query),
|
|
115
|
+
method: method !== null && method !== void 0 ? method : 'GET',
|
|
116
|
+
headers: headers,
|
|
117
|
+
responseType: resType,
|
|
118
|
+
transformResponse,
|
|
119
|
+
timeout: timeout,
|
|
120
|
+
data: data,
|
|
121
|
+
});
|
|
108
122
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
resolve(JSON.parse(request.response));
|
|
115
|
-
}
|
|
116
|
-
catch (ex) {
|
|
117
|
-
reject(new Error("Unable to parse response: " + request.response));
|
|
118
|
-
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
if (err.response) {
|
|
125
|
+
let errorData;
|
|
126
|
+
if (typeof err.response.data === 'object') {
|
|
127
|
+
errorData = JSON.stringify(err.response.data);
|
|
119
128
|
}
|
|
120
129
|
else {
|
|
121
|
-
|
|
130
|
+
errorData = err.response.data;
|
|
122
131
|
}
|
|
132
|
+
throw new HttpResponseError(`Http error response: (${err.response.status}) ${errorData}`, err.response.status, err.response.statusText, errorData, url + this.serialize(query));
|
|
123
133
|
}
|
|
124
134
|
else {
|
|
125
|
-
|
|
135
|
+
throw new Error(err);
|
|
126
136
|
}
|
|
127
|
-
};
|
|
128
|
-
request.ontimeout = function () {
|
|
129
|
-
reject(new Error("Request timed out after: " + request.timeout + "ms"));
|
|
130
|
-
};
|
|
131
|
-
request.onerror = function (err) {
|
|
132
|
-
reject(new HttpRequestFailed(url, err));
|
|
133
|
-
};
|
|
134
|
-
if (data) {
|
|
135
|
-
var dataStr = JSON.stringify(data);
|
|
136
|
-
request.send(dataStr);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
request.send();
|
|
140
137
|
}
|
|
138
|
+
return response.data;
|
|
141
139
|
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}());
|
|
140
|
+
}
|
|
141
|
+
}
|
|
145
142
|
exports.HttpBackend = HttpBackend;
|
|
146
143
|
//# sourceMappingURL=taquito-http-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-http-utils.js","sourceRoot":"","sources":["../../src/taquito-http-utils.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"taquito-http-utils.js","sourceRoot":"","sources":["../../src/taquito-http-utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAGH,iC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 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
5
|
-
/* tslint:disable */
|
|
6
5
|
exports.VERSION = {
|
|
7
|
-
"commitHash": "
|
|
8
|
-
"version": "
|
|
6
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
7
|
+
"version": "12.0.0-beta-RC.0"
|
|
9
8
|
};
|
|
10
|
-
/* tslint:enable */
|
|
11
9
|
//# sourceMappingURL=version.js.map
|
package/dist/lib/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC9D,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,kBAAkB;CAChC,CAAC"}
|
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
/*! *****************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
/**
|
|
2
29
|
* Hypertext Transfer Protocol (HTTP) response status codes.
|
|
3
30
|
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
|
|
@@ -319,24 +346,24 @@ var STATUS_CODE;
|
|
|
319
346
|
})(STATUS_CODE || (STATUS_CODE = {}));
|
|
320
347
|
|
|
321
348
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
"
|
|
325
|
-
|
|
326
|
-
};
|
|
327
|
-
/* tslint:enable */
|
|
349
|
+
const VERSION = {
|
|
350
|
+
"commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
|
|
351
|
+
"version": "12.0.0-beta-RC.0"
|
|
352
|
+
};
|
|
328
353
|
|
|
329
354
|
/**
|
|
330
355
|
* @packageDocumentation
|
|
331
356
|
* @module @taquito/http-utils
|
|
332
357
|
*/
|
|
333
|
-
|
|
334
|
-
var
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
358
|
+
const defaultTimeout = 30000;
|
|
359
|
+
var ResponseType;
|
|
360
|
+
(function (ResponseType) {
|
|
361
|
+
ResponseType["TEXT"] = "text";
|
|
362
|
+
ResponseType["JSON"] = "json";
|
|
363
|
+
})(ResponseType || (ResponseType = {}));
|
|
364
|
+
class HttpResponseError extends Error {
|
|
365
|
+
constructor(message, status, statusText, body, url) {
|
|
366
|
+
super(message);
|
|
340
367
|
this.message = message;
|
|
341
368
|
this.status = status;
|
|
342
369
|
this.statusText = statusText;
|
|
@@ -344,114 +371,99 @@ var HttpResponseError = /** @class */ (function () {
|
|
|
344
371
|
this.url = url;
|
|
345
372
|
this.name = 'HttpResponse';
|
|
346
373
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
374
|
+
}
|
|
375
|
+
class HttpRequestFailed extends Error {
|
|
376
|
+
constructor(url, innerEvent) {
|
|
377
|
+
super(`Request to ${url} failed`);
|
|
351
378
|
this.url = url;
|
|
352
379
|
this.innerEvent = innerEvent;
|
|
353
380
|
this.name = 'HttpRequestFailed';
|
|
354
|
-
this.message = "Request to " + url + " failed";
|
|
355
|
-
}
|
|
356
|
-
return HttpRequestFailed;
|
|
357
|
-
}());
|
|
358
|
-
var HttpBackend = /** @class */ (function () {
|
|
359
|
-
function HttpBackend() {
|
|
360
381
|
}
|
|
361
|
-
|
|
382
|
+
}
|
|
383
|
+
class HttpBackend {
|
|
384
|
+
serialize(obj) {
|
|
362
385
|
if (!obj) {
|
|
363
386
|
return '';
|
|
364
387
|
}
|
|
365
|
-
|
|
366
|
-
|
|
388
|
+
const str = [];
|
|
389
|
+
for (const p in obj) {
|
|
390
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
367
391
|
if (obj.hasOwnProperty(p) && typeof obj[p] !== 'undefined') {
|
|
368
|
-
|
|
392
|
+
const prop = typeof obj[p].toJSON === 'function' ? obj[p].toJSON() : obj[p];
|
|
369
393
|
// query arguments can have no value so we need some way of handling that
|
|
370
394
|
// example https://domain.com/query?all
|
|
371
395
|
if (prop === null) {
|
|
372
396
|
str.push(encodeURIComponent(p));
|
|
373
|
-
|
|
397
|
+
continue;
|
|
374
398
|
}
|
|
375
399
|
// another use case is multiple arguments with the same name
|
|
376
400
|
// they are passed as array
|
|
377
401
|
if (Array.isArray(prop)) {
|
|
378
|
-
prop.forEach(
|
|
402
|
+
prop.forEach((item) => {
|
|
379
403
|
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(item));
|
|
380
404
|
});
|
|
381
|
-
|
|
405
|
+
continue;
|
|
382
406
|
}
|
|
383
407
|
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(prop));
|
|
384
408
|
}
|
|
385
|
-
};
|
|
386
|
-
for (var p in obj) {
|
|
387
|
-
_loop_1(p);
|
|
388
409
|
}
|
|
389
|
-
|
|
410
|
+
const serialized = str.join('&');
|
|
390
411
|
if (serialized) {
|
|
391
|
-
return
|
|
412
|
+
return `?${serialized}`;
|
|
392
413
|
}
|
|
393
414
|
else {
|
|
394
415
|
return '';
|
|
395
416
|
}
|
|
396
|
-
}
|
|
397
|
-
HttpBackend.prototype.createXHR = function () {
|
|
398
|
-
return new XMLHttpRequestCTOR();
|
|
399
|
-
};
|
|
417
|
+
}
|
|
400
418
|
/**
|
|
401
419
|
*
|
|
402
420
|
* @param options contains options to be passed for the HTTP request (url, method and timeout)
|
|
403
421
|
*/
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
var request = _this.createXHR();
|
|
409
|
-
request.open(method || 'GET', "" + url + _this.serialize(query));
|
|
422
|
+
createRequest({ url, method, timeout = defaultTimeout, query, headers = {}, json = true }, data) {
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
let resType;
|
|
425
|
+
let transformResponse = undefined;
|
|
410
426
|
if (!headers['Content-Type']) {
|
|
411
|
-
|
|
427
|
+
headers['Content-Type'] = 'application/json';
|
|
412
428
|
}
|
|
413
|
-
if (
|
|
414
|
-
|
|
429
|
+
if (!json) {
|
|
430
|
+
resType = ResponseType.TEXT;
|
|
431
|
+
transformResponse = [(v) => v];
|
|
415
432
|
}
|
|
416
|
-
|
|
417
|
-
|
|
433
|
+
else {
|
|
434
|
+
resType = ResponseType.JSON;
|
|
418
435
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
436
|
+
let response;
|
|
437
|
+
try {
|
|
438
|
+
response = yield axios.request({
|
|
439
|
+
url: url + this.serialize(query),
|
|
440
|
+
method: method !== null && method !== void 0 ? method : 'GET',
|
|
441
|
+
headers: headers,
|
|
442
|
+
responseType: resType,
|
|
443
|
+
transformResponse,
|
|
444
|
+
timeout: timeout,
|
|
445
|
+
data: data,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
if (err.response) {
|
|
450
|
+
let errorData;
|
|
451
|
+
if (typeof err.response.data === 'object') {
|
|
452
|
+
errorData = JSON.stringify(err.response.data);
|
|
429
453
|
}
|
|
430
454
|
else {
|
|
431
|
-
|
|
455
|
+
errorData = err.response.data;
|
|
432
456
|
}
|
|
457
|
+
throw new HttpResponseError(`Http error response: (${err.response.status}) ${errorData}`, err.response.status, err.response.statusText, errorData, url + this.serialize(query));
|
|
433
458
|
}
|
|
434
459
|
else {
|
|
435
|
-
|
|
460
|
+
throw new Error(err);
|
|
436
461
|
}
|
|
437
|
-
};
|
|
438
|
-
request.ontimeout = function () {
|
|
439
|
-
reject(new Error("Request timed out after: " + request.timeout + "ms"));
|
|
440
|
-
};
|
|
441
|
-
request.onerror = function (err) {
|
|
442
|
-
reject(new HttpRequestFailed(url, err));
|
|
443
|
-
};
|
|
444
|
-
if (data) {
|
|
445
|
-
var dataStr = JSON.stringify(data);
|
|
446
|
-
request.send(dataStr);
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
request.send();
|
|
450
462
|
}
|
|
463
|
+
return response.data;
|
|
451
464
|
});
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
}());
|
|
465
|
+
}
|
|
466
|
+
}
|
|
455
467
|
|
|
456
468
|
export { HttpBackend, HttpRequestFailed, HttpResponseError, STATUS_CODE, VERSION };
|
|
457
|
-
//# sourceMappingURL=taquito-http-utils.
|
|
469
|
+
//# sourceMappingURL=taquito-http-utils.es6.js.map
|