Skip to content

Commit

Permalink
Merge pull request #982 from twenty20solutions/master
Browse files Browse the repository at this point in the history
Handle cases where `content-type` is not exactly `application/json`
  • Loading branch information
amanda11 committed Jul 22, 2022
2 parents 0496e93 + bb3a345 commit ecde497
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/st2-api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class API {
message: res.data.faultstring || res.data,
};
}

this.token = res.data;
}
catch (err) {
Expand Down Expand Up @@ -192,7 +192,8 @@ export class API {
params: query,
headers,
transformResponse: [ function transformResponse(data, headers) {
if (typeof data === 'string' && headers['content-type'] === 'application/json') {
if (typeof data === 'string' && headers['content-type'] &&
headers['content-type'].indexOf('application/json') > -1) {
try {
data = JSON.parse(data);
}
Expand All @@ -216,14 +217,14 @@ export class API {
},
// responseType: 'json',
};

if (this.rejectUnauthorized === false) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
}
else {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
}

const response = await axios(config);
const contentType = (response.headers || {})['content-type'] || [];
const requestId = (response.headers || {})['X-Request-ID'] || null;
Expand Down

0 comments on commit ecde497

Please sign in to comment.