n8n/packages/nodes-base/nodes/HttpRequest.node.ts

1004 lines
25 KiB
TypeScript
Raw Normal View History

import {
BINARY_ENCODING,
IExecuteFunctions,
} from 'n8n-core';
2019-06-23 03:35:23 -07:00
import {
IBinaryData,
2019-06-23 03:35:23 -07:00
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
NodeApiError,
NodeOperationError,
2019-06-23 03:35:23 -07:00
} from 'n8n-workflow';
import { OptionsWithUri } from 'request';
interface OptionData {
name: string;
displayName: string;
}
interface OptionDataParamters {
[key: string]: OptionData;
}
export class HttpRequest implements INodeType {
description: INodeTypeDescription = {
displayName: 'HTTP Request',
name: 'httpRequest',
icon: 'fa:at',
group: ['input'],
version: 1,
subtitle: '={{$parameter["requestMethod"] + ": " + $parameter["url"]}}',
2019-06-23 03:35:23 -07:00
description: 'Makes a HTTP request and returns the received data',
defaults: {
name: 'HTTP Request',
2019-06-23 03:35:23 -07:00
color: '#2200DD',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'httpBasicAuth',
required: true,
displayOptions: {
show: {
authentication: [
'basicAuth',
],
},
},
},
{
name: 'httpDigestAuth',
required: true,
displayOptions: {
show: {
authentication: [
'digestAuth',
],
},
},
},
2019-06-23 03:35:23 -07:00
{
name: 'httpHeaderAuth',
required: true,
displayOptions: {
show: {
authentication: [
'headerAuth',
],
},
},
},
{
name: 'oAuth1Api',
required: true,
displayOptions: {
show: {
authentication: [
'oAuth1',
],
},
},
},
{
name: 'oAuth2Api',
required: true,
displayOptions: {
show: {
authentication: [
'oAuth2',
],
},
},
},
2019-06-23 03:35:23 -07:00
],
properties: [
{
displayName: 'Authentication',
name: 'authentication',
type: 'options',
options: [
{
name: 'Basic Auth',
2020-10-22 06:46:03 -07:00
value: 'basicAuth',
2019-06-23 03:35:23 -07:00
},
{
name: 'Digest Auth',
2020-10-22 06:46:03 -07:00
value: 'digestAuth',
},
2019-06-23 03:35:23 -07:00
{
name: 'Header Auth',
2020-10-22 06:46:03 -07:00
value: 'headerAuth',
2019-06-23 03:35:23 -07:00
},
{
name: 'OAuth1',
2020-10-22 06:46:03 -07:00
value: 'oAuth1',
},
{
name: 'OAuth2',
2020-10-22 06:46:03 -07:00
value: 'oAuth2',
},
2019-06-23 03:35:23 -07:00
{
name: 'None',
2020-10-22 06:46:03 -07:00
value: 'none',
2019-06-23 03:35:23 -07:00
},
],
default: 'none',
description: 'The way to authenticate.',
},
{
displayName: 'Request Method',
name: 'requestMethod',
type: 'options',
options: [
{
name: 'DELETE',
2020-10-22 06:46:03 -07:00
value: 'DELETE',
2019-06-23 03:35:23 -07:00
},
{
name: 'GET',
2020-10-22 06:46:03 -07:00
value: 'GET',
2019-06-23 03:35:23 -07:00
},
{
name: 'HEAD',
2020-10-22 06:46:03 -07:00
value: 'HEAD',
2019-06-23 03:35:23 -07:00
},
{
name: 'PATCH',
2020-10-22 06:46:03 -07:00
value: 'PATCH',
},
2019-06-23 03:35:23 -07:00
{
name: 'POST',
2020-10-22 06:46:03 -07:00
value: 'POST',
2019-06-23 03:35:23 -07:00
},
{
name: 'PUT',
2020-10-22 06:46:03 -07:00
value: 'PUT',
2019-06-23 03:35:23 -07:00
},
],
default: 'GET',
description: 'The request method to use.',
},
{
displayName: 'URL',
name: 'url',
type: 'string',
default: '',
placeholder: 'http://example.com/index.html',
description: 'The URL to make the request to.',
required: true,
},
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Still download the response even if SSL certificate validation is not possible.',
},
2019-06-23 03:35:23 -07:00
{
displayName: 'Response Format',
name: 'responseFormat',
type: 'options',
options: [
{
name: 'File',
2020-10-22 06:46:03 -07:00
value: 'file',
},
2019-06-23 03:35:23 -07:00
{
name: 'JSON',
2020-10-22 06:46:03 -07:00
value: 'json',
2019-06-23 03:35:23 -07:00
},
{
name: 'String',
2020-10-22 06:46:03 -07:00
value: 'string',
2019-06-23 03:35:23 -07:00
},
],
default: 'json',
description: 'The format in which the data gets returned from the URL.',
},
{
displayName: 'Property Name',
name: 'dataPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
responseFormat: [
'string',
],
},
},
description: 'Name of the property to which to write the response data.',
},
{
displayName: 'Binary Property',
name: 'dataPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
responseFormat: [
'file',
],
},
},
description: 'Name of the binary property to which to<br />write the data of the read file.',
},
2019-06-23 03:35:23 -07:00
{
2019-11-02 02:12:59 -07:00
displayName: 'JSON/RAW Parameters',
2019-06-23 03:35:23 -07:00
name: 'jsonParameters',
type: 'boolean',
default: false,
description: 'If the query and/or body parameter should be set via the value-key pair UI or JSON/RAW.',
2019-06-23 03:35:23 -07:00
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Batch Interval',
name: 'batchInterval',
type: 'number',
typeOptions: {
minValue: 0,
},
default: 1000,
description: 'Time (in milliseconds) between each batch of requests. 0 for disabled.',
},
{
displayName: 'Batch Size',
name: 'batchSize',
type: 'number',
typeOptions: {
minValue: -1,
},
default: 50,
description: 'Input will be split in batches to throttle requests. -1 for disabled. 0 will be treated as 1.',
},
{
displayName: 'Body Content Type',
name: 'bodyContentType',
type: 'options',
displayOptions: {
show: {
'/requestMethod': [
'PATCH',
'POST',
'PUT',
],
},
},
options: [
{
name: 'JSON',
2020-10-22 06:46:03 -07:00
value: 'json',
},
2019-11-02 02:12:59 -07:00
{
name: 'RAW/Custom',
2020-10-22 06:46:03 -07:00
value: 'raw',
2019-11-02 02:12:59 -07:00
},
{
name: 'Form-Data Multipart',
2020-10-22 06:46:03 -07:00
value: 'multipart-form-data',
},
{
name: 'Form Urlencoded',
2020-10-22 06:46:03 -07:00
value: 'form-urlencoded',
},
],
default: 'json',
description: 'Content-Type to use to send body parameters.',
},
{
displayName: 'Full Response',
name: 'fullResponse',
type: 'boolean',
default: false,
description: 'Returns the full reponse data instead of only the body.',
},
{
displayName: 'Follow Redirect',
name: 'followRedirect',
type: 'boolean',
default: true,
description: 'Follow HTTP 3xx redirects.',
},
{
displayName: 'Ignore Response Code',
name: 'ignoreResponseCode',
type: 'boolean',
default: false,
description: 'Succeeds also when status code is not 2xx.',
},
{
displayName: 'MIME Type',
name: 'bodyContentCustomMimeType',
type: 'string',
default: '',
placeholder: 'text/xml',
description: 'Specify the mime type for raw/custom body type.',
required: false,
displayOptions: {
show: {
'/requestMethod': [
'PATCH',
'POST',
'PUT',
],
},
},
},
{
displayName: 'Proxy',
name: 'proxy',
type: 'string',
default: '',
placeholder: 'http://myproxy:3128',
description: 'HTTP proxy to use.',
},
{
displayName: 'Timeout',
name: 'timeout',
type: 'number',
typeOptions: {
minValue: 1,
},
default: 10000,
description: 'Time in ms to wait for the server to send response headers (and start the response body) before aborting the request.',
},
{
displayName: 'Use Querystring',
name: 'useQueryString',
type: 'boolean',
default: false,
description: 'Set this option to true if you need arrays to be serialized as foo=bar&foo=baz instead of the default foo[0]=bar&foo[1]=baz.',
},
],
},
// Body Parameter
2019-06-23 03:35:23 -07:00
{
displayName: 'Send Binary Data',
name: 'sendBinaryData',
type: 'boolean',
displayOptions: {
show: {
// TODO: Make it possible to use dot-notation
// 'options.bodyContentType': [
// 'raw',
// ],
jsonParameters: [
true,
],
requestMethod: [
'PATCH',
'POST',
'PUT',
],
},
},
default: false,
description: 'If binary data should be send as body.',
},
{
displayName: 'Binary Property',
name: 'binaryPropertyName',
type: 'string',
required: true,
default: 'data',
displayOptions: {
hide: {
sendBinaryData: [
false,
],
},
show: {
jsonParameters: [
true,
],
requestMethod: [
'PATCH',
'POST',
'PUT',
],
},
},
description: `Name of the binary property which contains the data for the file to be uploaded.<br />
For Form-Data Multipart, multiple can be provided in the format:<br />
"sendKey1:binaryProperty1,sendKey2:binaryProperty2`,
},
{
displayName: 'Body Parameters',
name: 'bodyParametersJson',
2019-06-23 03:35:23 -07:00
type: 'json',
displayOptions: {
hide: {
sendBinaryData: [
true,
],
},
2019-06-23 03:35:23 -07:00
show: {
jsonParameters: [
true,
],
requestMethod: [
'PATCH',
'POST',
'PUT',
],
2019-06-23 03:35:23 -07:00
},
},
default: '',
description: 'Body parameters as JSON or RAW.',
2019-06-23 03:35:23 -07:00
},
{
displayName: 'Body Parameters',
name: 'bodyParametersUi',
placeholder: 'Add Parameter',
2019-06-23 03:35:23 -07:00
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
jsonParameters: [
false,
],
requestMethod: [
'PATCH',
'POST',
'PUT',
],
2019-06-23 03:35:23 -07:00
},
},
description: 'The body parameter to send.',
2019-06-23 03:35:23 -07:00
default: {},
options: [
{
name: 'parameter',
displayName: 'Parameter',
2019-06-23 03:35:23 -07:00
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the parameter.',
2019-06-23 03:35:23 -07:00
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the parameter.',
2019-06-23 03:35:23 -07:00
},
2020-10-22 06:46:03 -07:00
],
2019-06-23 03:35:23 -07:00
},
],
},
// Header Parameters
2019-06-23 03:35:23 -07:00
{
displayName: 'Headers',
name: 'headerParametersJson',
2019-06-23 03:35:23 -07:00
type: 'json',
displayOptions: {
show: {
jsonParameters: [
true,
],
},
},
default: '',
description: 'Header parameters as JSON or RAW.',
2019-06-23 03:35:23 -07:00
},
{
displayName: 'Headers',
name: 'headerParametersUi',
placeholder: 'Add Header',
2019-06-23 03:35:23 -07:00
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
jsonParameters: [
false,
],
},
},
description: 'The headers to send.',
2019-06-23 03:35:23 -07:00
default: {},
options: [
{
name: 'parameter',
displayName: 'Header',
2019-06-23 03:35:23 -07:00
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the header.',
2019-06-23 03:35:23 -07:00
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value to set for the header.',
2019-06-23 03:35:23 -07:00
},
2020-10-22 06:46:03 -07:00
],
2019-06-23 03:35:23 -07:00
},
],
},
// Query Parameter
{
displayName: 'Query Parameters',
name: 'queryParametersJson',
type: 'json',
displayOptions: {
show: {
jsonParameters: [
true,
],
},
},
default: '',
description: 'Query parameters as JSON (flat object).',
},
{
displayName: 'Query Parameters',
name: 'queryParametersUi',
placeholder: 'Add Parameter',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
jsonParameters: [
false,
],
},
},
description: 'The query parameter to send.',
default: {},
options: [
{
name: 'parameter',
displayName: 'Parameter',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the parameter.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the parameter.',
},
2020-10-22 06:46:03 -07:00
],
2019-06-23 03:35:23 -07:00
},
],
},
2020-10-22 06:46:03 -07:00
],
2019-06-23 03:35:23 -07:00
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const fullReponseProperties = [
'body',
'headers',
'statusCode',
'statusMessage',
];
2019-06-23 03:35:23 -07:00
// TODO: Should have a setting which makes clear that this parameter can not change for each item
const requestMethod = this.getNodeParameter('requestMethod', 0) as string;
const parametersAreJson = this.getNodeParameter('jsonParameters', 0) as boolean;
const responseFormat = this.getNodeParameter('responseFormat', 0) as string;
2019-06-23 03:35:23 -07:00
const httpBasicAuth = this.getCredentials('httpBasicAuth');
const httpDigestAuth = this.getCredentials('httpDigestAuth');
2019-06-23 03:35:23 -07:00
const httpHeaderAuth = this.getCredentials('httpHeaderAuth');
const oAuth1Api = this.getCredentials('oAuth1Api');
const oAuth2Api = this.getCredentials('oAuth2Api');
2019-06-23 03:35:23 -07:00
let requestOptions: OptionsWithUri;
let setUiParameter: IDataObject;
const uiParameters: IDataObject = {
bodyParametersUi: 'body',
headerParametersUi: 'headers',
queryParametersUi: 'qs',
};
const jsonParameters: OptionDataParamters = {
bodyParametersJson: {
name: 'body',
displayName: 'Body Parameters',
},
headerParametersJson: {
name: 'headers',
displayName: 'Headers',
},
queryParametersJson: {
name: 'qs',
displayName: 'Query Paramters',
},
};
const returnItems: INodeExecutionData[] = [];
const requestPromises = [];
2019-06-23 03:35:23 -07:00
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
2020-03-17 05:18:04 -07:00
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
const url = this.getNodeParameter('url', itemIndex) as string;
if (itemIndex > 0 && options.batchSize as number >= 0 && options.batchInterval as number > 0) {
// defaults batch size to 1 of it's set to 0
const batchSize: number = options.batchSize as number > 0 ? options.batchSize as number : 1;
if (itemIndex % batchSize === 0) {
await new Promise(resolve => setTimeout(resolve, options.batchInterval as number));
}
}
const fullResponse = !!options.fullResponse as boolean;
2019-06-23 03:35:23 -07:00
requestOptions = {
headers: {},
method: requestMethod,
uri: url,
gzip: true,
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean,
2019-06-23 03:35:23 -07:00
};
if (fullResponse === true) {
// @ts-ignore
requestOptions.resolveWithFullResponse = true;
}
if (options.followRedirect !== undefined) {
requestOptions.followRedirect = options.followRedirect as boolean;
}
if (options.ignoreResponseCode === true) {
// @ts-ignore
requestOptions.simple = false;
}
if (options.proxy !== undefined) {
requestOptions.proxy = options.proxy as string;
}
if (options.timeout !== undefined) {
requestOptions.timeout = options.timeout as number;
} else {
requestOptions.timeout = 3600000; // 1 hour
}
if (options.useQueryString === true) {
requestOptions.useQuerystring = true;
}
2019-06-23 03:35:23 -07:00
if (parametersAreJson === true) {
// Parameters are defined as JSON
let optionData: OptionData;
for (const parameterName of Object.keys(jsonParameters)) {
optionData = jsonParameters[parameterName] as OptionData;
const tempValue = this.getNodeParameter(parameterName, itemIndex, '') as string | object;
2020-04-08 20:17:02 -07:00
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (optionData.name === 'body' && parametersAreJson === true) {
if (sendBinaryData === true) {
const contentTypesAllowed = [
'raw',
'multipart-form-data',
];
if (!contentTypesAllowed.includes(options.bodyContentType as string)) {
// As n8n-workflow.NodeHelpers.getParamterResolveOrder can not be changed
// easily to handle parameters in dot.notation simply error for now.
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), 'Sending binary data is only supported when option "Body Content Type" is set to "RAW/CUSTOM" or "FORM-DATA/MULTIPART"!');
}
const item = items[itemIndex];
if (item.binary === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
if (options.bodyContentType === 'raw') {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex) as string;
if (item.binary[binaryPropertyName] === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
}
const binaryProperty = item.binary[binaryPropertyName] as IBinaryData;
requestOptions.body = Buffer.from(binaryProperty.data, BINARY_ENCODING);
} else if (options.bodyContentType === 'multipart-form-data') {
requestOptions.body = {};
const binaryPropertyNameFull = this.getNodeParameter('binaryPropertyName', itemIndex) as string;
const binaryPropertyNames = binaryPropertyNameFull.split(',').map(key => key.trim());
for (const propertyData of binaryPropertyNames) {
let propertyName = 'file';
let binaryPropertyName = propertyData;
if (propertyData.includes(':')) {
const propertyDataParts = propertyData.split(':');
propertyName = propertyDataParts[0];
binaryPropertyName = propertyDataParts[1];
} else if (binaryPropertyNames.length > 1) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), 'If more than one property should be send it is needed to define the in the format: "sendKey1:binaryProperty1,sendKey2:binaryProperty2"');
}
if (item.binary[binaryPropertyName] === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
}
const binaryProperty = item.binary[binaryPropertyName] as IBinaryData;
requestOptions.body[propertyName] = {
value: Buffer.from(binaryProperty.data, BINARY_ENCODING),
options: {
filename: binaryProperty.fileName,
contentType: binaryProperty.mimeType,
},
};
}
}
continue;
}
}
if (tempValue === '') {
// Paramter is empty so skip it
continue;
}
2020-04-13 13:17:23 -07:00
// @ts-ignore
requestOptions[optionData.name] = tempValue;
2019-06-23 03:35:23 -07:00
// @ts-ignore
2019-11-02 02:12:59 -07:00
if (typeof requestOptions[optionData.name] !== 'object' && options.bodyContentType !== 'raw') {
// If it is not an object && bodyContentType is not 'raw' it must be JSON so parse it
2019-06-23 03:35:23 -07:00
try {
// @ts-ignore
requestOptions[optionData.name] = JSON.parse(requestOptions[optionData.name]);
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), `The data in "${optionData.displayName}" is no valid JSON. Set Body Content Type to "RAW/Custom" for XML or other types of payloads`);
2019-06-23 03:35:23 -07:00
}
}
}
} else {
// Paramters are defined in UI
let optionName: string;
for (const parameterName of Object.keys(uiParameters)) {
setUiParameter = this.getNodeParameter(parameterName, itemIndex, {}) as IDataObject;
optionName = uiParameters[parameterName] as string;
if (setUiParameter.parameter !== undefined) {
// @ts-ignore
requestOptions[optionName] = {};
for (const parameterData of setUiParameter!.parameter as IDataObject[]) {
// @ts-ignore
requestOptions[optionName][parameterData!.name as string] = parameterData!.value;
}
}
}
}
// Change the way data get send in case a different content-type than JSON got selected
if (['PATCH', 'POST', 'PUT'].includes(requestMethod)) {
if (options.bodyContentType === 'multipart-form-data') {
requestOptions.formData = requestOptions.body;
delete requestOptions.body;
} else if (options.bodyContentType === 'form-urlencoded') {
requestOptions.form = requestOptions.body;
delete requestOptions.body;
}
}
if (responseFormat === 'file') {
requestOptions.encoding = null;
if (options.bodyContentType !== 'raw') {
requestOptions.body = JSON.stringify(requestOptions.body);
if (requestOptions.headers === undefined) {
requestOptions.headers = {};
}
requestOptions.headers['Content-Type'] = 'application/json';
}
} else if (options.bodyContentType === 'raw') {
requestOptions.json = false;
} else {
requestOptions.json = true;
}
2019-11-02 02:12:59 -07:00
// Add Content Type if any are set
if (options.bodyContentCustomMimeType) {
if (requestOptions.headers === undefined) {
2019-11-02 02:12:59 -07:00
requestOptions.headers = {};
}
requestOptions.headers['Content-Type'] = options.bodyContentCustomMimeType;
2019-11-02 02:12:59 -07:00
}
2019-06-23 03:35:23 -07:00
// Add credentials if any are set
if (httpBasicAuth !== undefined) {
requestOptions.auth = {
user: httpBasicAuth.user as string,
pass: httpBasicAuth.password as string,
};
}
if (httpHeaderAuth !== undefined) {
requestOptions.headers![httpHeaderAuth.name as string] = httpHeaderAuth.value;
}
if (httpDigestAuth !== undefined) {
requestOptions.auth = {
user: httpDigestAuth.user as string,
pass: httpDigestAuth.password as string,
sendImmediately: false,
};
}
2019-06-23 03:35:23 -07:00
if (requestOptions.headers!['accept'] === undefined) {
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';
} else {
requestOptions.headers!['accept'] = 'application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7';
}
}
// Now that the options are all set make the actual http request
if (oAuth1Api !== undefined) {
requestPromises.push(this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions));
} else if (oAuth2Api !== undefined) {
requestPromises.push(this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, { tokenType: 'Bearer' }));
} else {
requestPromises.push(this.helpers.request(requestOptions));
}
}
// @ts-ignore
const promisesResponses = await Promise.allSettled(requestPromises);
let response: any; // tslint:disable-line:no-any
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
// @ts-ignore
response = promisesResponses.shift();
if (response!.status !== 'fulfilled') {
if (this.continueOnFail() !== true) {
// throw error;
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeApiError(this.getNode(), response);
} else {
// Return the actual reason as error
returnItems.push(
{
json: {
error: response.reason,
},
2020-10-22 09:00:28 -07:00
},
);
2020-03-17 05:18:04 -07:00
continue;
}
}
2019-06-23 03:35:23 -07:00
response = response.value;
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
const url = this.getNodeParameter('url', itemIndex) as string;
const fullResponse = !!options.fullResponse as boolean;
if (responseFormat === 'file') {
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
const newItem: INodeExecutionData = {
json: {},
binary: {},
};
if (items[itemIndex].binary !== undefined) {
// Create a shallow copy of the binary data so that the old
// data references which do not get changed still stay behind
// but the incoming data does not get changed.
Object.assign(newItem.binary, items[itemIndex].binary);
}
const fileName = (url).split('/').pop();
if (fullResponse === true) {
const returnItem: IDataObject = {};
for (const property of fullReponseProperties) {
if (property === 'body') {
continue;
}
returnItem[property] = response![property];
}
newItem.json = returnItem;
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(response!.body, fileName);
} else {
newItem.json = items[itemIndex].json;
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(response!, fileName);
}
returnItems.push(newItem);
} else if (responseFormat === 'string') {
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
if (fullResponse === true) {
const returnItem: IDataObject = {};
for (const property of fullReponseProperties) {
if (property === 'body') {
returnItem[dataPropertyName] = response![property];
continue;
}
returnItem[property] = response![property];
}
returnItems.push({ json: returnItem });
} else {
returnItems.push({
json: {
[dataPropertyName]: response,
},
});
}
2019-06-23 03:35:23 -07:00
} else {
// responseFormat: 'json'
if (fullResponse === true) {
const returnItem: IDataObject = {};
for (const property of fullReponseProperties) {
returnItem[property] = response![property];
}
if (responseFormat === 'json' && typeof returnItem.body === 'string') {
try {
returnItem.body = JSON.parse(returnItem.body);
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), 'Response body is not valid JSON. Change "Response Format" to "String"');
}
}
returnItems.push({ json: returnItem });
} else {
if (responseFormat === 'json' && typeof response === 'string') {
try {
response = JSON.parse(response);
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), 'Response body is not valid JSON. Change "Response Format" to "String"');
}
}
returnItems.push({ json: response });
}
2019-06-23 03:35:23 -07:00
}
}
return this.prepareOutputData(returnItems);
2019-06-23 03:35:23 -07:00
}
}