Add list and list-entry resources to Affinity Node (#1387)

This commit is contained in:
Ricardo Espinoza
2021-01-30 12:47:27 -05:00
committed by GitHub
parent 05df13a887
commit db417da464
6 changed files with 506 additions and 40 deletions

View File

@@ -1,4 +1,6 @@
import { OptionsWithUri } from 'request';
import {
OptionsWithUri,
} from 'request';
import {
BINARY_ENCODING,
@@ -6,7 +8,11 @@ import {
ILoadOptionsFunctions,
} from 'n8n-core';
import { IDataObject, IHookFunctions, IWebhookFunctions } from 'n8n-workflow';
import {
IDataObject,
IHookFunctions,
IWebhookFunctions,
} from 'n8n-workflow';
export async function affinityApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
@@ -38,12 +44,13 @@ export async function affinityApiRequest(this: IExecuteFunctions | IWebhookFunct
delete options.qs;
}
options = Object.assign({}, options, option);
console.log(options);
try {
return await this.helpers.request!(options);
} catch (error) {
if (error.response) {
const errorMessage = error.response.body.message || error.response.body.description || error.message;
throw new Error(`Affinity error response: ${errorMessage}`);
throw new Error(`Affinity error response [${error.statusCode}]: ${errorMessage}`);
}
throw error;
}