Skip to content

Commit ecde497

Browse files
authored
Merge pull request #982 from twenty20solutions/master
Handle cases where `content-type` is not exactly `application/json`
2 parents 0496e93 + bb3a345 commit ecde497

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

modules/st2-api/api.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class API {
108108
message: res.data.faultstring || res.data,
109109
};
110110
}
111-
111+
112112
this.token = res.data;
113113
}
114114
catch (err) {
@@ -192,7 +192,8 @@ export class API {
192192
params: query,
193193
headers,
194194
transformResponse: [ function transformResponse(data, headers) {
195-
if (typeof data === 'string' && headers['content-type'] === 'application/json') {
195+
if (typeof data === 'string' && headers['content-type'] &&
196+
headers['content-type'].indexOf('application/json') > -1) {
196197
try {
197198
data = JSON.parse(data);
198199
}
@@ -216,14 +217,14 @@ export class API {
216217
},
217218
// responseType: 'json',
218219
};
219-
220+
220221
if (this.rejectUnauthorized === false) {
221222
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
222223
}
223224
else {
224225
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
225226
}
226-
227+
227228
const response = await axios(config);
228229
const contentType = (response.headers || {})['content-type'] || [];
229230
const requestId = (response.headers || {})['X-Request-ID'] || null;

0 commit comments

Comments
 (0)