Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissive parsing of post and response data #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/apis/avantation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ export class AvantationAPI implements Avantation.InputConfig {
switch (postData.mimeType.split(';')[0].toLocaleLowerCase()) {
case 'application/json':
case 'application/json; charset=utf-8':
let data = postData.text ? JSON.parse(postData.text) : {};
let data;
try {
data = postData.text ? JSON.parse(postData.text) : {};
} catch(e) {
this.oclif.warn(`Unable to parse post data ${e}`);
break;
}
param.content[postData.mimeType] = {
schema: Util.generateSchema(data),
example: data
Expand Down Expand Up @@ -310,7 +316,13 @@ export class AvantationAPI implements Avantation.InputConfig {
res.content.text = Buffer.from(res.content.text, 'base64').toString();
}

let responseData = JSON.parse(res.content.text);
let responseData;
try {
responseData = JSON.parse(res.content.text);
} catch(e) {
this.oclif.warn(`Unable to parse post response data ${e}`);
return response;
}
if (responseData instanceof Array) {
responseData = responseData.slice(0, 3);
} else {
Expand Down