@portal-hq/utils 0.2.22-beta2 → 0.2.23
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.
|
@@ -26,7 +26,7 @@ class HttpRequest {
|
|
|
26
26
|
this.request.onreadystatechange = () => {
|
|
27
27
|
if (this.request.readyState === 4) {
|
|
28
28
|
// readyState 4 means the request has completed
|
|
29
|
-
if (this.request.status
|
|
29
|
+
if (this.request.status >= 300) {
|
|
30
30
|
// If we didn't get an 'OK' status, error out
|
|
31
31
|
reject(new errors_1.HttpError({
|
|
32
32
|
message: this.request.responseText,
|
|
@@ -54,21 +54,19 @@ class HttpRequest {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
prepareBody() {
|
|
57
|
-
if (this.headers['Content-Type']
|
|
58
|
-
//
|
|
59
|
-
return JSON.stringify(this.body);
|
|
60
|
-
}
|
|
61
|
-
else if (this.headers['Content-Type'].includes('multipart/related')) {
|
|
62
|
-
return this.body;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// Otherwise, build a serialized string
|
|
57
|
+
if (!this.headers['Content-Type']) {
|
|
58
|
+
// Build a serialized string if no Content-Type is provided
|
|
66
59
|
const params = [];
|
|
67
60
|
for (const [key, value] of Object.entries(this.body)) {
|
|
68
61
|
params.push(`${key}=${value}`);
|
|
69
62
|
}
|
|
70
63
|
return params.join('&');
|
|
71
64
|
}
|
|
65
|
+
else if (this.headers['Content-Type'] === 'application/json') {
|
|
66
|
+
// Stringify if we're declaring this request to be a JSON request
|
|
67
|
+
return JSON.stringify(this.body);
|
|
68
|
+
}
|
|
69
|
+
return this.body;
|
|
72
70
|
}
|
|
73
71
|
prepareRequest() {
|
|
74
72
|
// Add all of the defined headers to the request
|
|
@@ -24,7 +24,7 @@ class HttpRequest {
|
|
|
24
24
|
this.request.onreadystatechange = () => {
|
|
25
25
|
if (this.request.readyState === 4) {
|
|
26
26
|
// readyState 4 means the request has completed
|
|
27
|
-
if (this.request.status
|
|
27
|
+
if (this.request.status >= 300) {
|
|
28
28
|
// If we didn't get an 'OK' status, error out
|
|
29
29
|
reject(new HttpError({
|
|
30
30
|
message: this.request.responseText,
|
|
@@ -52,21 +52,19 @@ class HttpRequest {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
prepareBody() {
|
|
55
|
-
if (this.headers['Content-Type']
|
|
56
|
-
//
|
|
57
|
-
return JSON.stringify(this.body);
|
|
58
|
-
}
|
|
59
|
-
else if (this.headers['Content-Type'].includes('multipart/related')) {
|
|
60
|
-
return this.body;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// Otherwise, build a serialized string
|
|
55
|
+
if (!this.headers['Content-Type']) {
|
|
56
|
+
// Build a serialized string if no Content-Type is provided
|
|
64
57
|
const params = [];
|
|
65
58
|
for (const [key, value] of Object.entries(this.body)) {
|
|
66
59
|
params.push(`${key}=${value}`);
|
|
67
60
|
}
|
|
68
61
|
return params.join('&');
|
|
69
62
|
}
|
|
63
|
+
else if (this.headers['Content-Type'] === 'application/json') {
|
|
64
|
+
// Stringify if we're declaring this request to be a JSON request
|
|
65
|
+
return JSON.stringify(this.body);
|
|
66
|
+
}
|
|
67
|
+
return this.body;
|
|
70
68
|
}
|
|
71
69
|
prepareRequest() {
|
|
72
70
|
// Add all of the defined headers to the request
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@ class HttpRequest {
|
|
|
38
38
|
this.request.onreadystatechange = () => {
|
|
39
39
|
if (this.request.readyState === 4) {
|
|
40
40
|
// readyState 4 means the request has completed
|
|
41
|
-
if (this.request.status
|
|
41
|
+
if (this.request.status >= 300) {
|
|
42
42
|
// If we didn't get an 'OK' status, error out
|
|
43
43
|
reject(
|
|
44
44
|
new HttpError({
|
|
@@ -68,13 +68,8 @@ class HttpRequest {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
private prepareBody(): any {
|
|
71
|
-
if (this.headers['Content-Type']
|
|
72
|
-
//
|
|
73
|
-
return JSON.stringify(this.body)
|
|
74
|
-
} else if (this.headers['Content-Type'].includes('multipart/related')) {
|
|
75
|
-
return this.body
|
|
76
|
-
} else {
|
|
77
|
-
// Otherwise, build a serialized string
|
|
71
|
+
if (!this.headers['Content-Type']) {
|
|
72
|
+
// Build a serialized string if no Content-Type is provided
|
|
78
73
|
const params = []
|
|
79
74
|
|
|
80
75
|
for (const [key, value] of Object.entries(this.body)) {
|
|
@@ -82,7 +77,12 @@ class HttpRequest {
|
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
return params.join('&')
|
|
80
|
+
} else if (this.headers['Content-Type'] === 'application/json') {
|
|
81
|
+
// Stringify if we're declaring this request to be a JSON request
|
|
82
|
+
return JSON.stringify(this.body)
|
|
85
83
|
}
|
|
84
|
+
|
|
85
|
+
return this.body
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
private prepareRequest(): void {
|