mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Apply Dali's suggestions
This commit is contained in:
parent
f5ff3d212b
commit
0143bca54c
|
@ -60,7 +60,19 @@ export async function zohoApiRequest(
|
|||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
|
||||
let responseData = await this.helpers.requestOAuth2?.call(this, 'zohoOAuth2Api', options);
|
||||
|
||||
if (responseData === undefined) return [];
|
||||
|
||||
throwOnErrorStatus.call(this, responseData);
|
||||
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
if (['create', 'delete', 'update', 'get'].includes(operation)) {
|
||||
responseData = responseData.data[0];
|
||||
}
|
||||
|
||||
return responseData;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
|
@ -85,9 +97,9 @@ export async function zohoApiRequestAllItems(
|
|||
|
||||
do {
|
||||
responseData = await zohoApiRequest.call(this, method, endpoint, body, qs, uri);
|
||||
if (!responseData) return [];
|
||||
if (Array.isArray(responseData) && !responseData.length) return returnData;
|
||||
returnData.push(...responseData.data);
|
||||
uri = responseData.info.more_records;
|
||||
returnData.push.apply(returnData, responseData['data']);
|
||||
qs.page++;
|
||||
} while (
|
||||
responseData.info.more_records !== undefined &&
|
||||
|
@ -126,6 +138,15 @@ export function throwOnEmptyUpdate(this: IExecuteFunctions, resource: string) {
|
|||
);
|
||||
}
|
||||
|
||||
export function throwOnErrorStatus(
|
||||
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
|
||||
responseData: { data?: Array<{ status: string, message: string }> },
|
||||
) {
|
||||
if (responseData?.data?.[0].status === 'error') {
|
||||
throw new NodeOperationError(this.getNode(), responseData as Error);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// required field adjusters
|
||||
// ----------------------------------------
|
||||
|
|
|
@ -8,6 +8,8 @@ import {
|
|||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
|
@ -23,6 +25,7 @@ import {
|
|||
adjustVendorPayload,
|
||||
handleListing,
|
||||
throwOnEmptyUpdate,
|
||||
throwOnErrorStatus,
|
||||
toLoadOptions,
|
||||
zohoApiRequest,
|
||||
zohoApiRequestAllItems,
|
||||
|
@ -1001,7 +1004,7 @@ export class ZohoCrm implements INodeType {
|
|||
|
||||
Array.isArray(responseData)
|
||||
? returnData.push(...responseData)
|
||||
: returnData.push(...responseData.data);
|
||||
: returnData.push(responseData);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue