🔀 Merge branch 'master' into oauth-support

This commit is contained in:
Jan Oberhauser
2020-04-10 09:47:12 +02:00
20 changed files with 1650 additions and 433 deletions

View File

@@ -183,7 +183,6 @@ export class HttpRequest implements INodeType {
default: 'json',
description: 'The format in which the data gets returned from the URL.',
},
{
displayName: 'Property Name',
name: 'dataPropertyName',
@@ -650,9 +649,9 @@ export class HttpRequest implements INodeType {
// Paramter is empty so skip it
continue;
}
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (optionData.name === 'body' && parametersAreJson === true) {
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (sendBinaryData === true) {
const contentTypesAllowed = [
@@ -714,8 +713,12 @@ export class HttpRequest implements INodeType {
}
}
// @ts-ignore
requestOptions[optionData.name] = tempValue;
try {
// @ts-ignore
requestOptions[optionData.name] = JSON.parse(tempValue as string);
} catch (error) {
throw new Error(`${optionData.name} must be a valid JSON`);
}
// @ts-ignore
if (typeof requestOptions[optionData.name] !== 'object' && options.bodyContentType !== 'raw') {
@@ -783,6 +786,7 @@ export class HttpRequest implements INodeType {
}
if (responseFormat === 'json') {
requestOptions.headers!['accept'] = 'application/json,text/*;q=0.99';
} else if (responseFormat === 'string') {
requestOptions.headers!['accept'] = 'application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, */*;q=0.1';
@@ -797,9 +801,6 @@ export class HttpRequest implements INodeType {
} else {
requestOptions.json = true;
}
// Now that the options are all set make the actual http request
try {
// Now that the options are all set make the actual http request
@@ -873,7 +874,7 @@ export class HttpRequest implements INodeType {
returnItems.push({
json: {
[dataPropertyName]: response,
}
},
});
}
} else {
@@ -884,14 +885,22 @@ export class HttpRequest implements INodeType {
returnItem[property] = response[property];
}
if (typeof returnItem.body === 'string') {
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
if (responseFormat === 'json' && typeof returnItem.body === 'string') {
try {
returnItem.body = JSON.parse(returnItem.body);
} catch (e) {
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
}
}
returnItems.push({ json: returnItem });
} else {
if (typeof response === 'string') {
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
if (responseFormat === 'json' && typeof response === 'string') {
try {
response = JSON.parse(response);
} catch (e) {
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
}
}
returnItems.push({ json: response });