mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
⚡ Small improvements
This commit is contained in:
parent
baac8edeb0
commit
d76e90541d
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
@ -9,10 +10,12 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
linkFields,
|
linkFields,
|
||||||
linkOperations
|
linkOperations
|
||||||
} from './LinkDescription';
|
} from './LinkDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bitlyApiRequest,
|
bitlyApiRequest,
|
||||||
bitlyApiRequestAllItems,
|
bitlyApiRequestAllItems,
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IExecuteSingleFunctions,
|
IExecuteSingleFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
import { IDataObject } from 'n8n-workflow';
|
|
||||||
import { attachmentFields } from '../Salesforce/AttachmentDescription';
|
import {
|
||||||
|
IDataObject,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||||
|
@ -33,11 +38,19 @@ export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions |
|
||||||
|
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} else {
|
} else {
|
||||||
//@ts-ignore
|
|
||||||
return await this.helpers.requestOAuth2!.call(this, 'bitlyOAuth2Api', options, 'Bearer');
|
return await this.helpers.requestOAuth2!.call(this, 'bitlyOAuth2Api', options, { tokenType: 'Bearer' });
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
throw new Error(error);
|
|
||||||
|
if (error.response && error.response.body && error.response.body.message) {
|
||||||
|
// Try to return the error prettier
|
||||||
|
const errorBody = error.response.body;
|
||||||
|
throw new Error(`Bitly error response [${error.statusCode}]: ${errorBody.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expected error data did not get returned so throw the actual error
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue