🔀 Merge branch 'RicardoE105-feature/extended-http-node'

This commit is contained in:
Jan Oberhauser 2020-04-10 00:44:31 +02:00
commit c042909d89

View file

@ -168,7 +168,6 @@ export class HttpRequest implements INodeType {
default: 'json', default: 'json',
description: 'The format in which the data gets returned from the URL.', description: 'The format in which the data gets returned from the URL.',
}, },
{ {
displayName: 'Property Name', displayName: 'Property Name',
name: 'dataPropertyName', name: 'dataPropertyName',
@ -634,9 +633,9 @@ export class HttpRequest implements INodeType {
// Paramter is empty so skip it // Paramter is empty so skip it
continue; continue;
} }
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (optionData.name === 'body' && parametersAreJson === true) { if (optionData.name === 'body' && parametersAreJson === true) {
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (sendBinaryData === true) { if (sendBinaryData === true) {
const contentTypesAllowed = [ const contentTypesAllowed = [
@ -698,8 +697,12 @@ export class HttpRequest implements INodeType {
} }
} }
// @ts-ignore try {
requestOptions[optionData.name] = tempValue; // @ts-ignore
requestOptions[optionData.name] = JSON.parse(tempValue as string);
} catch (error) {
throw new Error(`${optionData.name} must be a valid JSON`);
}
// @ts-ignore // @ts-ignore
if (typeof requestOptions[optionData.name] !== 'object' && options.bodyContentType !== 'raw') { if (typeof requestOptions[optionData.name] !== 'object' && options.bodyContentType !== 'raw') {
@ -767,6 +770,7 @@ export class HttpRequest implements INodeType {
} }
if (responseFormat === 'json') { if (responseFormat === 'json') {
requestOptions.headers!['accept'] = 'application/json,text/*;q=0.99'; requestOptions.headers!['accept'] = 'application/json,text/*;q=0.99';
} else if (responseFormat === 'string') { } else if (responseFormat === 'string') {
requestOptions.headers!['accept'] = 'application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, */*;q=0.1'; requestOptions.headers!['accept'] = 'application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, */*;q=0.1';
@ -781,7 +785,6 @@ export class HttpRequest implements INodeType {
} else { } else {
requestOptions.json = true; requestOptions.json = true;
} }
try { try {
// Now that the options are all set make the actual http request // Now that the options are all set make the actual http request
response = await this.helpers.request(requestOptions); response = await this.helpers.request(requestOptions);
@ -850,7 +853,7 @@ export class HttpRequest implements INodeType {
returnItems.push({ returnItems.push({
json: { json: {
[dataPropertyName]: response, [dataPropertyName]: response,
} },
}); });
} }
} else { } else {
@ -861,14 +864,22 @@ export class HttpRequest implements INodeType {
returnItem[property] = response[property]; returnItem[property] = response[property];
} }
if (typeof returnItem.body === 'string') { if (responseFormat === 'json' && typeof returnItem.body === 'string') {
throw new Error('Response body is not valid JSON. Change "Response Format" to "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 }); returnItems.push({ json: returnItem });
} else { } else {
if (typeof response === 'string') { if (responseFormat === 'json' && typeof response === 'string') {
throw new Error('Response body is not valid JSON. Change "Response Format" to "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 }); returnItems.push({ json: response });